The following subsections are ordered from simple actions to more elaborate or rarer actions.
Linking to category pages To link to a category page
without putting the current page in that category, precede the link with a colon: [[:Category:
Category name]]. Such a link can be
piped like a normal wikilink. (The {{
cl}} template, and others listed on its documentation page, may sometimes be helpful.)
Retrieving raw category information Raw information about the members of a category, their sortkeys and timestamps (time when last added to the category) can be obtained from the
API, using a query of the form:
https://en.wikipedia.org/w/api.php?cmtitle=Category:Category_name&action=query&list=categorymembers&cmlimit=500&cmprop=title|sortkey|timestamp
Listings of up to 500 members are possible. If there are more members then the results will include text near the end like this:
<categorymembers cmcontinue="page|NNNN|TITLE" />
.This can be added to the previous one, without quotation marks, for the next page of members: ...&cmcontinue=page|NNNN|TITLE
By default, a page is sorted under the first character of its name, without the namespace. English Wikipedia groups accented characters together with their unaccented version, so pages starting with À, Á, Ä, will be listed under heading A. Sorting is case-insensitive, so "ABC" comes after "Abacus".
The English Wikipedia has
numerical sorting in categories. This means a page whose title begins with a number will be sorted according to the numeric value of the number (even if it is multiple digits). Thus "9 dogs", "25 dogs", and "112 dogs" will all appear under the "0–9" heading in numeric order. If the number includes a comma, space, or period, the sorting algorithm will only consider the part of the number before the separator.
Each of the three lists (subcategories, pages, media files) is arranged in the order explained above (except that, in the subcategories list, the namespace indicator "Category:" is not considered). If an item ought to be positioned within a list on the basis of an alternative name (sort key) for that item, then this can be specified in the category tag that places the item in the list:
[[Category:Category name|Sortkey]]
[[Category:1879 births|Einstein, Albert]]
Unlike a
piped link (which uses the same syntax), the sort key itself is not displayed to readers. It affects only the order in which pages are listed on the category page.
It is useful to document the system being used for sort keys on the category page. For guidelines about the use of sort keys on Wikipedia, see
WP:SORTKEY.
It is possible to set a default sort key which is different from
{{PAGENAME}} by using the
magic word {{DEFAULTSORT}}:
{{DEFAULTSORT:new key}}
This is often used in biography articles, to make sure the subject is sorted by their last name:
{{DEFAULTSORT:LastName, FirstName}}
In the case of multiple default sort key tags, the last DEFAULTSORT on the final rendering of a page applies for all categories, regardless of the position of the category tags. This also means that a DEFAULTSORT tag included from a template is not effective if another DEFAULTSORT tag occurs later on the page, even if the later DEFAULTSORT tag is also "hidden" (included by another template). If a category is added inside
<ref>...</ref> then
DEFAULTSORT may be ignored.
Searching for pages in categories In addition to browsing through hierarchies of categories, it is possible to use the search tool to find specific articles in specific categories. To search for articles in a specific category, type incategory:"CategoryName" in the search box.
A pipe "|" can be added to join the contents of one category with the contents of another. For example, enter
incategory:"Suspension bridges|Bridges in New York City"
to return all pages that belong to either (or both) of the categories, as
here.
Note that using search to find categories will not find articles which have been categorized using templates. This feature also doesn't return pages in subcategories.
Special:Categories provides an alphabetic list of all categories, with the number of members of each; this number does not include the content of the subcategories, but it includes the subcategories themselves, i.e., each counting as one.
The above list contains all categories that have members, regardless of whether they have corresponding category pages. To list all existing category pages (regardless of whether they have members), use
Special:AllPages/Category:.
Displaying category trees and page counts As described at
mw:Help:Magic words,
{{PAGESINCATEGORY:Example}}
or{{PAGESINCAT:Example}}
returns the number of pages in "Category:Example". Each subcategory counts as one page; pages in subcategories are not counted.
The page
Special:CategoryTree enables you to see the tree structure of a category (its subcategories, their subcategories and so on; the display of files and other member pages is optional).
The
CategoryTree extension can be used to display such a tree on any page. (This is sometimes done on the category page itself, if the category is split over multiple screens, to make all subcategories available on every screen.) The basic syntax is
<categorytree>Category name</categorytree>
to display just the subcategory tree, and
<categorytree mode=pages>Category name</categorytree>
to display member pages as well. They will be indicated by italics.
Dapete's category-visualizer
vCat will render charts of the tree structure.
Warning:
The following code {{PAGESINCATEGORY:{{PAGENAME}}}} will not work as expected when used in the wikitext or in a transcluded template in a category page whose title contains some ASCII punctuations.
For legacy reasons, {{PAGENAME}} may return the page name with these characters being HTML-encoded using numeric character entities : this still works for generating derived wikilinks or displaying page names, or when HTML-encoded this page name is used in a conditional "#switch", but PAGESINCATEGORY does not recognize the category name given in parameter if some characters are HTML-encoded (this is the case notably when the category name contains ASCII apostrophes ' and a few other ASCII punctuations. (The same HTML-encoding is also applied to the values returned by {{FULLPAGENAME}}, {{SUBPAGENAME}}, or {{NAMESPACE}}).
In that case, as the category is not found by its HTML-encoded pagename, PAGESINCATEGORY will unexpectedly return 0 and not its effective number of member pages.
A simple workaround is to transform these HTML-encoded characters back into standard UTF-8-encoded characters, by using the {{titleparts:}} parser function, like this:
{{PAGESINCATEGORY:{{titleparts:{{PAGENAME}}}}}}
Moving and redirecting category pages Categories can be moved in the same way as an ordinary page; but a certain amount of cleanup may be necessary. A redirect is left at the old category name, and this is not a normal
#REDIRECT [[...]] but a
. Once all the pages have been moved out of the old category, it may be left as a category redirect or deleted. For categories entirely populated through templates (see above), modifying the templates enables all affected articles to be moved to another category, but with the refresh problem mentioned. Almost all category name changes are made pursuant to a consensus decision at
Wikipedia:Categories for discussion.
Do not create intercategory redirects other than with a
template. See
Wikipedia:Categories for discussion#Redirecting categories for more on category redirects.
When the
magic word __HIDDENCAT__ is placed on a category page, that category becomes
hidden, meaning that it will not be displayed on the pages belonging to that category. On Wikipedia, the magic word is not normally used explicitly, but is applied through the {{
hidden category}} template. The feature is mostly used to prevent project maintenance categories from showing up to ordinary readers on article pages.
However, hidden categories are displayed (although listed as hidden):
- on category pages (whether as parent categories or subcategories);
- at preview during editing;
- if the user has selected "Show hidden categories" in user preferences.
For guidelines on the hiding of categories on Wikipedia, see
WP:HIDDENCAT.