Difference between revisions of "Anchors - Mediawiki"

From Help Wiki
m (subst applied to Template:TwoColumn)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
It is possible to link to a specific portion of a page.
+
__NOTOC__
  
==Setting anchors==
+
<div class="container-fluid">
===Automatic anchors===
+
<div class="row">
 +
<div class="col-md-8">
 +
<div class="lead">
 +
Anchors allow you to link to a specific portion of a page.
 +
</div>
 +
 
 +
===Setting anchors===
 +
====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.
 
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===
+
====Using the <nowiki>{{anchor}}</nowiki> template====
Manually-set anchors are useful for linking to "unlinkable" things like a table (title or cell), a section of plain text, etc.  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, <nowiki><div id="what_to_link_to">text</div></nowiki> or <nowiki><div id="what_to_link_to"/>text</nowiki>
+
#set your anchor anywhere in the page by using
For example, in the [[#Wiki-link Tricks|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 <code><nowiki>[[#Wikilink Tricks & Demos]]</nowiki></code> will not work.
+
<pre>{{anchor|anchorname}}</pre>
  
 +
====Manual anchors====
 +
Manually-set anchors are useful for linking to "unlinkable" things like a table (title or cell), a section of plain text, etc. 
 
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 [[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.
Line 17: Line 24:
 
* 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===
+
* On some wikis, a [[Templates - Mediawiki|template]] called "anchor" exists, providing a simple, standardized method for that wiki. The Self Study wiki does use [[Template:Anchor]].
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 [http://en.wikipedia.org/wiki/Calendar_date#Big_endian_forms.2C_starting_with_the_year]), with leading zeros (see also [http://meta.wikimedia.org/wiki/Help:Date_formatting_and_linking#Link_to_date_content_other_than_required_for_autoformatting]). 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.  
+
  
==Referencing anchors==
+
===Referencing anchors===
 
Inside a regular wiki link <nowiki>[[page#anchor_name|shows_as]]</nowiki>, include the hash sign (#) and the header name or the id tag name as you have written it.
 
Inside a regular wiki link <nowiki>[[page#anchor_name|shows_as]]</nowiki>, include the hash sign (#) and the header name or the id tag name as you have written it.
  
 
Links of the form <code><nowiki>[[#anchor_name]]</nowiki></code> will link to the first anchor on the page matching that "anchor_name", usually the first identical section heading.
 
Links of the form <code><nowiki>[[#anchor_name]]</nowiki></code> will link to the first anchor on the page matching that "anchor_name", usually the first identical section heading.
 +
 +
;See also
 +
*http://meta.wikimedia.org/wiki/Help:Link#Anchors
  
  
Line 29: Line 38:
 
{{Template:Anchor}}
 
{{Template:Anchor}}
  
 +
 +
<!-- end col-md-8 -->
 +
</div>
 +
<div class="col-md-1"></div>
 +
<div class="col-md-3 sidebar">
 +
{{GetHelp}}
 +
 +
<!-- end col-md-3-->
 +
</div>
 +
<!-- end row-->
 +
</div>
 +
<!-- end container-->
 +
</div>
 +
<!-- Generator=Template:TwoColumn -->
 +
__NOTOC__
 +
__NOEDITSECTION__
 
  [[category:Mediawiki]]
 
  [[category:Mediawiki]]

Latest revision as of 17:00, 14 August 2017


Anchors allow you to link to a specific portion of a page.

Setting anchors

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.

Using the {{anchor}} template

  1. set your anchor anywhere in the page by using
{{anchor|anchorname}}

Manual anchors

Manually-set anchors are useful for linking to "unlinkable" things like a table (title or cell), a section of plain text, etc. There are a number of ways to set an anchor at an arbitrary position:

  • Generic anchor: <span id="anchor_name">some text</span>. For a hidden anchor, omit the text.
  • On some wikis, a template called "anchor" exists, providing a simple, standardized method for that wiki. The Self Study wiki does use Template:Anchor.

Referencing anchors

Inside a regular wiki link [[page#anchor_name|shows_as]], include the hash sign (#) and the header name or the id tag name as you have written it.

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.

See also