Professional Documents
Culture Documents
Section Linking: Replacing The Default TOC
Section Linking: Replacing The Default TOC
Section Linking: Replacing The Default TOC
Same page:
o wikicode: [[#toc|Contents]]
o link: Contents
a related template: {{Back to contents}}
Back to contents
Different page:
o wikicode: [[Help:Wiki markup#toc|Contents]]
o link: Contents
Replacing the default TOC
The auto-generated TOC is not maximally appropriate or useful in all article types, such as long list
articles and glossaries, so there are numerous replacement templates. To use one,
put __NOTOC__ at the top of the article, and place the alternative TOC template, such
as {{Compact ToC}} (which can be customized for many list styles) where needed.
Horizontal TOC
The template {{Horizontal TOC}} lays out the TOC in a horizontal list rather than a vertical one. It can
be practical in a TOC with many brief entries. The ability to display a long TOC without scrolling
makes it suited for tables where the rows contain section headings.
Example: Legality of cannabis by country – uses a concise but functional A–Z horizontal
TOC.
Example: Legality of cannabis by U.S. jurisdiction – uses two TOCs; a short, vertical one,
and a long, horizontal one.
Section linking
In the HTML code for each section there is an "id" attribute holding the section title. This
enables linking directly to sections. These section anchors are automatically used by
MediaWiki when it generates a table of contents for the page, and therefore when a section
heading in the ToC is clicked, it will jump to the section. Also, the section anchors can be
manually linked directly to one section within a page.
The HTML code generated at the beginning of this section, for example, is:
(NB section links are case sensitive, including the first character (Help:Link).)
To link to a section in the same page you can use [[#section name|displayed
text]] , and to link to a section in another page [[page name#section name|
displayed text]] .
The anchors disregard the depth of the section; a link to a subsection or sub-subsection
etc. will be [[#subsection name]] and [[#sub-subsection name]] etc.
An underscore and number are appended to duplicate section names. E.g. for three
sections named "Example", the names (for section linking) will be "Example",
"Example_2" and "Example_3". However, after editing section "Example_2" or
"Example_3" (see below), one, confusingly, arrives at section "Example" from the edit
summary.
If a section has a blank space as heading, it results in a link in the TOC that does not
work. For a similar effect see NS:0.
To create an anchor target without a section heading, you can use the {{anchor}}
template or a span: <span id="anchor_name"></span> .
To format a link to a section with a section sign ("§") rather than with "#" or custom text,
use {{Section link}} (or {{slink}}). For example, {{Section link|Foo|Bar}} is equivalent
to a Foo#Bar link, but is formatted Foo § Bar.
Notes:
An internal link in a section heading does not cause complications to section linking;
however, editors who have their preferences set to edit sections by clicking on the
header will not be able to click these links:
o #Demo a
o Help:Section#Demo http://a
o http://meta.wikimedia.org/wiki/Help:Section#Demo_http:.2F.2Fa
The pipe trick does not work for section links:
o [[#section| ]] ->
o [[page#section| ]] ->
o [[namespace:page#section| ]] ->
Instead of linking directly to a section, link to a page that redirects to the section;
when the name of the section is changed, just change the redirect target. With this
method, pages linking to the section can be identified by using What links here on
the redirect page. The tools:~dispenser/cgi-bin/rdcheck.py tool can be used to find
existing section redirects.
Use a manual anchor when you wish to link to a section, so that you do not have to
rely on the section name being stable.
Put a comment in the wikitext at the start of a section listing pages that link to the
section.
Make the section a separate page/template and either transclude it into, or just link
to it from, its parent page; instead of linking to the section one can then link to the
separate page.
Redirect pages can be categorized by adding a category tag after the redirect
command. In the case that the target of the redirect is a section, this has to some extent
the effect of categorizing the section: through the redirect the category page links to the
section; however, unless an explicit link is put, the section does not link to the category.
On the category page, redirects are displayed with class redirect-in-category, so they
can be shown in e.g. italics; this can be defined in MediaWiki:Common.css. See
also WP:Categorizing redirects.
Section editing
Shortcuts
WP:EDITLINK
WP:SECTIONEDIT
Sections can be separately edited by clicking special edit links labeled "[edit]" by the
heading or by right clicking on the section heading. This is called "section editing".
The section editing feature will take you to an edit page by a URL such as
https://en.wikipedia.org/w/index.php?title=Help:Section&action=edit§ion=13
Note that here section numbers are used, not section titles; subsections have a single
number, e.g., section 2.1 may be numbered 3, section 3 is then numbered 4, etc. You
can also directly type in such URLs in the address bar of your browser.
This is convenient if the edit does not involve other sections and one needs not have the
text of other sections at hand during the edit. (But if one does need the article during a
section edit, you could open the section "edit" link in a new window, or during section
editing, open the article or page in a different window). Section editing alleviates some
problems of large pages by making it slightly faster and much easier to find the text that
you want to change.[2] It also may help when the full page is just too large for the
browser to handle all-at-once in the editor.
Shortcut
WP:NOEDITLINK
Adding the code __NOEDITSECTION__ anywhere on the page will remove the edit
links. It will not disable section editing itself; the URL can still be accessed manually.
Inserting a section can be done by editing either the section before or after it. An editor
can merge one section with the previous section by deleting the heading. Note that in
these cases the preloaded section name in the edit summary is not correct, and has to
be changed or deleted.
WP:+
Navigation on pages from "talk" namespaces provides a special link labeled "New
section", "+", or "Add topic" used to create a new section to the end of the page. [3] Pages
having the code __NEWSECTIONLINK__ in wikitext also display this link, regardless of
the namespace.
The URL for such an action looks like:
https://en.wikipedia.org/w/index.php?
title=Wikipedia:Sandbox&action=edit§ion=new.
In this case, a text box having as title "Subject/headline", will appear and the content
you type in it will become the name of the new section heading. There is no input box
for the edit summary; it is automatically created. Do not edit the last existing section to
create a new one, because it will result in a misleading edit summary which will conceal
creation of the section and may confuse other users.
See also linking in an edit summary to a section, "Post a comment" feature.
Editing before the first section
By default, there is no link to edit the lead section of a page, so the entire page must
be edited. Lead section editing can be enabled through Preferences → Gadgets →
Appearance → Add an [edit] link for the lead section of a page.