Template:Citation Style documentation/anchors

Anchored citations
This citation template can be used in or. It does this by creating an HTML anchor containing an ID that can be linked to from within the body of the article. This is done by use of the ref parameter.

By default, this template does not generate an ID. For most purposes, harv is used to created an ID from the term, plus last names of the first four authors, or the last names of the first four editors, plus the year or date. Examples:

Some editors may choose to place multiple authors into one parameter. Punctuation is encoded thus the output is not as expected. Example:

It is highly recommended that the last1 through last9 or editor1-last through editor1-last4 parameters be used when anchors are desired.

Where there may not be an author or date, then ID is used to generate a user defined ID.

It is highly recommended that the ID begin with CITEREF, as this will allow error checking tools to function. A custom ID must follow these rules:


 * Names may not start with a number.
 * The only characters that may be used used unencoded are letters A–Z, a–z, and digits 0–9.
 * Inclusion of any other characters will result in them being dot encoded.
 * It is recommended that names be kept simple and restricted to the standard English alphabet and numerals.

Dates
This templates supports date, year and month. It is important to use these parameters properly to prevent a malformed ID.
 * Month, day, year: Use date
 * Year only: Use year
 * Year and month: Use year and month

If a year only is used in date, then it may be interpreted as a time, and the ID will not be as expected.

{{markup

. The special parameter {{para|ref|harv}} generates an ID suitable for Harvard referencing templates such as {{tl|harv}} as specified in the next section; this is the default for the {{tl|citation}} template. If an empty {{para|ref}} is given, no anchor is generated; this is the default for the Cite templates such as {{tl|cite book}} and {{tl|cite news}}. You can also specify the ID directly, using the {{para|ref| ID }} parameter. For example, suppose an article's References section contains the markup: which generates the citation: Then, the markup " " generates a parenthetical reference "(Freud 1930)" containing a wikilink to the citation (try clicking on the wikilink).
 * {{Citation |author=Sigmund Freud |title=Civilization and Its Discontents |year=1930 |ref=CivDis}}

Anchors for Harvard referencing templates
IDs compatible with Harvard referencing templates such as harv are computed from the last names of the authors and the year of the cited source. For example, the markup " " generates the Harvard reference "", which wikilinks to the citation whose markup and appearance are shown below: In this example the citation template defines, and the harv template uses, the HTML ID " ", composed by concatenating the string " " with the last names of the authors and the year. The harvid template can be used to generate such IDs, for example,  generates " ".

Related methods which leave only a number in the text are to use the harvnb template enclosed in the html code, or to use the sfn template alone. The example above would be  or   both of which generate a footnote, such as
 * 17.

The names of only the first four authors are used; other author names are not concatenated to the ID. If no author names are given, editor names are used instead. For patents, inventor names are used instead of authors or editors. If these names are not given, this template does not generate an anchor.

Last names are used, as specified by the parameters last1 (or last), last2, last3, and last4, and similarly for editor1-last etc. and for inventor1-last etc. If a full name is given but no last name is specified, this template falls back on the full name, but this usage is not recommended. For example, in " " no last name is given, so this citation cannot be combined with the Harvard reference " ". To make these citation and harv invocations compatible, either replace "Sigmund Freud" with "Sigmund Freud", or add "ref" to the citation invocation, or add the same ref parameter (say, "EgoId") to both the citation and the harv invocations.

Similarly, the year is used, as specified by year. If no year is given, this template attempts to derive the year from date (or, if no date is given, from publication-date) by applying the MediaWiki#time function. This heuristic works with many common date formats (American, International and ISO standard format YYYY-MM-DD as listed in WP:MOS), but may not work as expected with other formats, so when in doubt it may be safer to use year. Note that if only a year, say 2005, is known you must use 2005 rather than 2005.

IDs must be unique
Names, years, and hand-specified IDs must be chosen so that the IDs are unique within a page; otherwise the HTML will not conform to the W3C standards, and any references to the citations will not work reliably. For example, suppose a page contains the following two citations with harv-compatible IDs:

If these citations were altered to say "2008" rather than "2008a" and "2008b", the resulting page would not work, because the two different citations would both attempt to use the ID " ". To avoid this problem, distinguish the citations by appending suffixes to the years, e.g., "2008a" and "2008b", as was done above. Any Harvard references to these citations should use years with the same suffixes.

It is good practice to verify that a page does not contain duplicate IDs by using the W3C Markup Validation Service; see External links.