Difference between revisions of "Anchors - Mediawiki"
(→Manual anchors) |
|||
Line 13: | Line 13: | ||
There are a number of ways to set an anchor at an arbitrary position: | There are a number of ways to set an anchor at an arbitrary position: | ||
− | * On some wikis, a [[template]] called "anchor" exists | + | * On some wikis, a [[Templates - Mediawiki|template]] called "anchor" exists, providing a simple, standardized method for that wiki. |
* Generic anchor: <code><nowiki><span id="anchor_name">some text</span></nowiki></code>. For a hidden anchor, omit the text. | * Generic anchor: <code><nowiki><span id="anchor_name">some text</span></nowiki></code>. For a hidden anchor, omit the text. | ||
− | |||
− | |||
* The reserved name <code><nowiki>[[#top]]</nowiki></code> always links to the [[#top|top of a page]]. | * The reserved name <code><nowiki>[[#top]]</nowiki></code> always links to the [[#top|top of a page]]. | ||
− | |||
===Index-style anchors=== | ===Index-style anchors=== |
Revision as of 11:58, 8 October 2007
It is possible to link to a specific portion of a page.
Contents
Setting anchors
- Headers automatically become html anchors, which can be linked to.
- The <a> tag is not allowed in Mediawiki, so we can't do the <a name="link here">, but we can do the "id" html attribute to almost any existing tag. For example, <div id="what_to_link_to">text</div> or <div id="what_to_link_to"/>text.
Automatic anchors
Section headings automatically act as anchors, with the heading text as the "anchor_name". In the case of multiple sections with identical headings, the anchor name of each has "_2", "_3", etc. appended, starting from the second occurrence.
Manual anchors
Manually-set anchors are useful for linking to "unlinkable" things like a table (title or cell), a section of plain text, etc. For example, in the Wikilink Tricks & Demos table above, though the "Wikilink Tricks & Demos" title-text appears like a (minor) heading, it is not, and the otherwise perfectly normal wikilink [[#Wikilink Tricks & Demos]]
will not work.
There are a number of ways to set an anchor at an arbitrary position:
- On some wikis, a template called "anchor" exists, providing a simple, standardized method for that wiki.
- Generic anchor:
<span id="anchor_name">some text</span>
. For a hidden anchor, omit the text.
- The reserved name
[[#top]]
always links to the top of a page.
Index-style anchors
If anchor names have multiple components, it is useful to put the most significant component first, e.g. if anchors indicate months or dates, we could have the format YYYY-MM, or YYYY-MM-DD, or in a year page MM-DD (see also [1]), with leading zeros (see also [2]). This applies also for page names, but since these are highly visible, as opposed to anchors, other considerations play a role too. In the case of sections, if for link targets another naming scheme is desired than for display of section headings, explicitly put anchors instead of using section names. This is applied in w:Portal:Current events/DateHeader2, where the use in links of the names of explicitly put anchors is enforced by using pseudo sections, with displayed headings that cannot be used as anchors.
Referencing anchors
Inside a regular wiki link [[page#anchor_name|shown_up_as]], include the hash sign (#) and the header name or the id tag name as you have written it.
Linking to a position in an external page
The HTML source of the target page needs to have <a name=..> or <.. id=..> at the target item as anchor to link to. Thus linking to a position in an external page for which this is not the case yet, one needs control over the target page, or cooperation of one who has.
Linking to anchors
Links of the form [[#anchor_name]]
will link to the first anchor on the page matching that "anchor_name", usually the first identical section heading.
An #anchor_name can also be appended to the page name in any type of link, thus linking to the first identical section heading (or anchor) of the named page: