Help:Category
Categories, a software feature of MediaWiki, provide automatic indexes that are useful as tables of contents.
Together with links and templates they structure a project.
Contents
- 1 Summary
- 2 Putting an item in a category
- 3 Category page
- 4 Creating a category page
- 5 Sort order
- 6 See also
- 7 Categories and templates
- 8 Categorizing redirect pages
- 9 Moving a category page
- 10 List of all categories
- 11 Visualizing category tree
- 12 Applying "Related changes" to a category
- 13 Comparison with "What links here"
- 14 Category considerations
- 15 Extensions
- 16 Count
- 17 Links to other help pages
Summary[edit]
Each of the pages in the Category namespace represents a so-called category, a grouping of related pages, and contains an index for the pages of its category. For example, this page belongs to "Category:English documentation". If you open the "Category:English documentation" page, you will see a link to this page there.
When a page belongs to one or more categories, these categories appear at the bottom of the page (or in the upper-right corner, depending on the skin being used).
The category pages themselves contain 2 parts:
- at their beginning, an optional part may contain text that can be edited, like any other page,
- at their end, an ever present, automatically generated, alphabetical list of all pages in that category, in the form of links. (In fact, in ASCII order. See Help:Special page).
To assign a category to a page, simply add the link "[[Category:Category name]]" to the page's wikitext. The usual place to add it is at the bottom of the page.
To link a category page within a page as a normal wiki link (without adding the page to the category), prefix the link name with a colon. For example: [[:Category:Not in this category|Display Label]]
New categories can be created before assigning any page to it, in the same way as any other regular page.
Individual wikis may have their own top-level categories, such as w:Category:Contents in Wikipedia.
For a complete list of all categories which have at least one page, see Special:Categories.
For a complete list of all categories, including the ones that don't have any page, see Special:Allpages/Category: (note the colon at the end).
For categories on Meta, see m:Meta:Categories.
Putting an item in a category[edit]
A page in any namespace can be put in a category by adding a category tag to the page (by convention, at the end of the page), e.g.:
[[Category:Category name]]
You must substitute the actual name of your desired category in place of Category name. For example, to add an article called "Albert Einstein" to the category "People", you would edit the Albert Einstein article and add "[[Category:People]]" (no quotes) into its page source somewhere.
This will cause the page to be automatically listed on the associated category page, and it will also create a link in the page to the category page. Category pages are always in the namespace "Category". Pages can be included in more than one category by adding multiple category tags. These links do not appear at the location where you inserted the tag, but at the page margin in a fixed place, depending on the skin (the bottom for MonoBook, the upper right corner for Standard).
Category tags may be placed anywhere in the wikitext, but they are typically added near the end. On Wikipedia the policy is that category tags are put after the main wikitext, but before any interlanguage links.
Category links are displayed in the order in which they occur in the wikitext.
Hidden categories[edit]
When __HIDDENCAT__ is put on a category page, that category is not listed on the pages within it. See category:hidden category demo and hidden category demo for an example.
However, hidden categories can be made visible by ticking the item Show hidden categories
(described by message with id 'tog-showhiddencats' (talk)) in the "Misc" section in the user's preference; either way they can be made visible or invisible through CSS(details needed).
The hidden categories that a page belongs to are listed using the label supplied by the message with id 'hiddencategories' (talk) when editing the page.
Hidden categories are automatically added to the category specified by the message with id 'hidden-category-category' (talk) (This is called a tracking category). In this wiki it is Category:Hidden categories. Within the Category namespace, the hidden categories a category page belongs to are listed separately from the standard (non-hidden) categories it also belongs to, using the label specified by the message with id 'hidden-categories' (talk). [See category:hidden category demo 1.]
For example, suppose a page is categorised under MyHiddenCategory
. The page itself does not mention this categorisation unless tog-showhiddencats
is true, in which case the listing hiddencategories
appears below the standard Categories listing (the specific positioning depends on the skin, obviously). Within the Category namespace, MyHiddenCat
is listed under the hidden-category-category
global category. If MyHiddenCat
has sub-categories, these will each list MyHiddenCat
under the hidden-categories
listing, appearing below the standard category listing. If MyHiddenCat
is itself categorised under some higher category, the latter lists it without making any particular distinction (that is to say, hidden sub-categories are listed just as if they were standard sub-categories).
Category page[edit]
A category page can consist of up to four parts:
- editable text
- list of subcategories; how many there are is also displayed; if there are no subcategories the header and count are not shown. Clicking the arrow in front of the subcategory name will display the pages and subcategories contained.
- list of pages (showing the full pagename) in the category; if there are none the header is shown anyway. Subcategories and images are not considered pages here and appear in their own separate lists above and below. (A raw list without links or headers can be obtained with Special:Export.)
- list of image and other media files with thumbnails; the number of files is given and the first 20 characters of the file name are shown, with an ellipsis if that is not the full name; also the file size is shown. (As opposed to the second and third section, this section does not have sub-headers per letter of the alphabet.)
Only the list of pages is always shown. All other parts of the category page are optional.
The items in the lists all link to the pages concerned; in the case of the images this applies both to the image itself and to the text below it (the name of the image).
The first and second list each have a header for each first character, dispensed with if there are no entries for a header. (If no headers are desired, use sort keys all starting with a blank space; see below.)
The number of items in each list is shown at the top of each. There are up to 200 items on a page, for the three types subcategories, pages and images together. If the category contains more, only the first 200 items in the over-all order are displayed, for example the subcategories, pages and media files with implicit or explicit sortkeys A-C, etc. Also a link to the page containing the following 200 items is offered on the bottom of the page.
On Meta and Wikipedia a redirect to a category shows the editable text only. To get the full page after being redirected, use the link "Image", or "Category", respectively.
On Commons a redirect to a category gives the full page, but not the subcategories and pages in the redirect page (if that is also a category).
Creating a category page[edit]
To create a category page, one can e.g:
- follow an automatically created link to the category page. Putting this code on any page creates the link.
[[Category:Category name]]
or:
- add a colon in front of the Category tag when you set up the page-creation link, to prevent the software from thinking you merely want to add the page you are working on to the category:
[[:Category:Category name]]
Placing the above text on a working page will create the link you can use to edit your category page, and will display the link text as a normal wiki link without adding the page to the category.
Subcategories[edit]
Creating subcategories takes only a few additional steps. Adding a category tag to a category page makes the edited category a subcategory of the category specified in the tag.
First create a new category page for the subcategory the same way you would make a regular category. For example, create [[Category:England]]
Then go to the newly created category page and edit it. Add the category tag for the parent category (e.g. [[Category:Country]]) to the page.
Then create a new page with a category link to England. In this example, the England category would then be a subcategory of the Country category.
e.g. adding link to the new page like this...
[[Category:England]]
Now to create a subcategory to subcategory England you need to create a new page with a category link to England wikipage and edit it (the category).
e.g. adding link to the page like this...
[[Category:London]]
For a live example see Category:Demo_1 which is a subcategory of Category:Demo.
Sort order[edit]
Each of the three lists is in an order according to an implicit sort key, a default sort key for all category tags on a page, or an explicit sort key in a category tag. The implicit sort key is the full pagename, except for subcategories, where the namespace and the colon are not included.
The sort order is based on capitalised names, using alphabetical order, or more precisely Unicode order. The ranges 32–96, 123–127 correspond to ASCII, for more see a table of Unicode characters:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'{|}~
Note in particular that "Z" comes before accented / umlauted characters.
Although in Special:Allpages and Special:Prefixindex a blank space within a page name is treated as an underscore, and therefore comes after the capitals, and before the lower case letters, this does not apply in category pages: there a space counts as space. Compare the order of Help:Demo1 and Help:Demo a (both without a specified sort key) on Category:Demo and [1].
Sort key[edit]
An explicit sort key is specified in the category tag that places the item in the list:
[[Category:category_name|sort_key]]
For example to add an article called Albert Einstein to the category "people" and have the article sorted by "Einstein, Albert", you would type "[[Category:People|Einstein, Albert]]".
Although this is like the syntax for a piped link (and in an edit summary it is interpreted like one), there is a clear difference: the second term in the piped link is an alternative term for the first one, while the sort key is an alternative name for the page in which the tag occurs. Also, a piped link influences the rendering of the page itself, while a sort key affects the rendering of another page.
The displayed name is not changed. The sort keys themselves are not visible on the category page. An explanation of the sort key system used can be useful on the editable part of a category page.
The sort key system should be obvious, otherwise the order seems random and items are hard to find. The system should either be consistently applied to all members of a category, or be such that the listings of members on which it is applied fit in well within the list of members for which no sort key is used. The latter is advisable for large, growing categories with many contributors. See also below.
A common system is starting with the last name, then a comma and a space, and then the first name; note that any additions such as "Jr." should come at the end, otherwise the entry would come before the same without the addition, because a space comes before a comma.
In e.g. w:Category:Denmark, the sort key of a page consists of the keywords, without "Danish" or "of Denmark", "in Denmark", etc.
For the gallery of images in a category the prefix "Image:" is part of the default sort key. E.g. for Image:AlbertEinstein.jpg we can code
- [[Category:People|Image:Einstein, Albert]]
to sort the image between Image:D.. and Image:F.. without explicit sort key. If we code
- [[Category:People|Einstein, Albert]]
it comes before all images without explicit sort key.
The sort key is no longer case sensitive. Never more. Forget this problem. :) . But the remaining adjustment required is the replacement of non-English accented characters, such as "ź" with English counterparts, e.g. "z". It means that non Latin or accented characters are sorted after the "z".
In sort keys spaces are relevant; also a double space is distinguished from a single one. For example, " A
" starting with two blank spaces comes before " A
" starting with one. Also * comes before letters and digits.
An underscore in a sort key is distinct from a blank space.
Non-main namespaces[edit]
Now all pages are by default sorted by name, despite the namespace. For example, in a category of templates the template:delete is listed by D. Forget this problem too :).
Default sort key[edit]
[MW1.10+] It is possible to set a default sort key which is different from {{PAGENAME}} by using the magic word {{DEFAULTSORT}} thus:
{{DEFAULTSORT:new key}}
In the case of multiple default sort key tags, the last one on a page applies for all categories, regardless of the position of the category tags. This also means that a DEFAULTSORT tag in a template, intended for category tags in that template, for categorization of pages calling the template, is not effective if another DEFAULTSORT tag occurs later on these pages, even if it is also "hidden", in another template.
See also[edit]
See also w:wp:sortkey.
Grouping of pages by using sort keys[edit]
If e.g. in a list of people sort keys like "scientist Einstein, Albert" are used then all scientists are listed together under the "s". Unfortunately no separate heading "scientist(s)" is possible, and salesmen would be under the same heading. Alternatively "scientist" can have e.g. code K (to be explained in the editable part of the category page) and the sort key "K Einstein, Albert" is used.
Categories and templates[edit]
Templates can make using and maintaining category pages much simpler.
Adding a category by using a template[edit]
A template can be used to add a page to a category (one specially for this, or one with another purpose as well), usually by placing the category link inside <includeonly></includeonly> tags on the template (e.g. <includeonly>[[Category:category name]]</includeonly>
). When the template is transcluded into the page, the category link becomes active, and the page is added to the category page. This is useful for categories that have high turnover or many pages included, like cleanup categories, because:
- it helps keep category lists up-to-date
- it provides a consistent format so that pages end up on the correct category page without error
- it can be easier
Changes to the template, however, may not be reflected immediately on the category page. When you edit an article to add a category tag directly, the list of category members is updated immediately when the page is saved. When a category link is contained in a template, however, this does not happen immediately: instead, whenever a template is edited, all the pages that transclude it are put into the job queue to be recached during periods of low server load (but see The Mediawiki Manual, which appears to contradict this, emptying the queue only at periods of high server load). This means that, in busy periods, it may take hours or even days before individual pages are recached and they start to appear in the category list. Performing a null edit to a page will allow it to 'jump the queue' and be immediately recached.
If it is necessary to add the template itself to the category page as well, the 'includeonly' tags can be omitted, but this is generally not desired.
Sort keys in templates[edit]
A sort key can be passed as parameter to a template and applied to the category link as shown above. Sort keys can also depend on variables (notably PAGENAME) or calls to other templates.
Categorizing templates[edit]
Templates themselves can be categorized - without affecting the pages that call them - by putting the category link inside <noinclude></noinclude> tags (e.g. <noinclude>[[Category:category name]]</noinclude>
). The 'noinclude' tags specify that the link applies only to the template, and is not included during transclusion. If the page uses the standard {{documentation}} template, these template-only category links are often placed in the documentation, where indicated.
A similar effect can be achieved with ParserFunctions: {{#ifeq:{{FULLPAGENAME}}|Template:Editthispage|[[Category:category name|{{PAGENAME}}]]|}}, but it is a bit more complex.
Selective category inclusion[edit]
Sometimes it is useful to be selective about which pages get added to the category page. For instance, we may want article pages to be added to the category, but not other pages, or we may want the user to select a particular category by passing a parameter. Both of these effects (and others) can be achieved.
Specifying a category with a parameter:
<includeonly>[[category:{{{cat|default}}}]]</includeonly>
If the user provides a parameter 'cat=XXX' the page will be categorized at the page [[Category:XXX]], otherwise it will be categorized at the page [[Category:default]]. Calling the template with "cat=" disables putting the page in any category.
Excluding non-article pages:
<includeonly>{{#if:{{NAMESPACE}}||[[Category:XXX]]}}</includeonly>
produces a category tag for pages in the main namespace only.
Categorizing redirect pages[edit]
Redirect pages can be categorized. The category tag has to be put in the first paragraph. 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 article containing the section does not automatically link back 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 w:Wikipedia:Categorizing redirects .
Moving a category page[edit]
The only way to move a category page is to manually change all category tags that link to the category, and copy the editable part of the category. There is no automatic way to move a category page in the way one moves an article page.
The editable first part of a category can be moved like any other page, but that won't move the subcategories, articles, and images in the second, third, and fourth part (see above). For categories entirely populated through templates (see above) modifying the templates allows to move all affected articles to a renamed category (but with the refresh problem mentioned).
List of all categories[edit]
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. Comparing with http://meta.wikimedia.org/w/index.php?title=Special%3AAllpages&namespace=14 :
- a category without members is not in the former
- a category that has not been created as a page is not in the latter (in the former it stands out as red link)
Visualizing category tree[edit]
Special:CategoryTree enables you to visualize the tree structure of categories. The CategoryTree extension installed on MediaWiki allows in-page display of the tree.
<categorytree mode=pages>Africa</categorytree> gives
<categorytree mode=pages hideroot=on>Africa</categorytree> gives
Dapete's category-visualizer Catgraph will render charts of the tree structure.
Applying "Related changes" to a category[edit]
For a category the "Related changes" feature gives the changes in the pages in the category (according to the current category page, so excluding the pages that have potentially been added and including those that have potentially been removed, through addition or deletion of a template to/from the category, as explained above)
- for subcategories: the changes in their editable parts only
- for images (image pages): the changes in their editable parts only.
It does not show the changes in pages linked from the editable parts of the category. Possible workarounds:
- The editable part can be put in a template. The category tags (which have no effect on Related changes anyway) can better be kept out of the template, because on the pages of these supercategories the template would be listed under the articles in those categories. Whether interwiki links (with or without interlanguage link feature) are in the template or not does not make a difference, provided that the template is not used elsewhere.
- Related changes is applied to a page that calls the category as a template: {{:Category:Category name}}; only the editable part is included in the page; the page could be specially created for this purpose and call multiple categories. However, this page will then be listed in the supercategory pages of each category.
As usual (but as opposed to a watchlist) the changes in the corresponding talk pages are not shown.
Applying "Related changes" to a category, with sufficiently high limits on number and days, is also useful for checking which pages in a category one "watches": they are bolded.
If the category contains pages but does not "exist" as editable page, "Related changes" can be applied, but no link is supplied, one has to supply the URL oneself. It is more convenient to "create" the page first.
For the "What links here" feature, only the links in the editable part of the page count, not the links to the pages in the category.
Dynamic page list[edit]
The DynamicPageList2 extension provides a list of last edits to the pages in a category, or optionally, just the list of pages; the simpler DynamicPageList is installed on Meta and Wikinews; the version DPLforum is installed on Wikia, see http://www.wikia.com/wiki/Help:Forums.
Detection of additions to a category[edit]
By checking "Related changes" from a category page one can find pages which are newly in a category due to addition of a category tag or the tag of a template that is in the category. Addition of pages through addition to the category of a template is seen indirectly: one can see the change in the template, and then check which pages call the template. This even shows pages which are only potentially in the category (see above).
Unfortunately there is no similar way to detect a deletion from a category.
Comparison with "What links here"[edit]
Backlinks are often used as a by-product of links and inclusions. However, links and inclusion tags can be put specially for the backlinks, just like category tags are.
Thus one can create a kind of "category abc" showing its content with Special:Whatlinkshere/abc without an entry in the category lists on each page in the category. With inclusion this can be done in two ways:
- {{#if:|{{:abc}}}} rendering nothing. This works regardless of whether abc exists.
- {{:abc}}. This requires creating a blank page to render nothing, or a page with some content to provide an in-page category listing.
- In the case of links
- A redirect corresponds to a supercategory.
- Advantages of categories
-
- Category listings are alphabetical, for "What links here" this typically applies for the first part only, for the pages already linking to the given page at the time of the last rebuilding of the link tables in the database.
- Categories have an editable part (however, there is anyway a talk page)
- A category can have multiple supercategories
- Advantage of a pseudo-category system using backlinks
-
- Backlinks can show a tree structure: not only pages and subcategories, but also the contents of the subcategories (for each a list of pages and a list of sub-subcategories) and the contents of the sub-subcategories (for each a list of pages and a list of sub-sub-subcategories), but not the contents of the sub-sub-subcategories, up to three levels are shown.
- In the case of inclusions
-
- also multiple supercategories are possible
- combined content of subcategories is shown in one list, not grouped by subcategory (the tree structure is not shown, but it can be used by taking the backlinks at a lower node, showing the smaller set)
- the restriction of three levels (in the case of using redirects) does not apply; for example page Aijkl in the category Aijk in the category Aij in the category Ai in the category A (represented by Aijkl calling template Aijk, etc.) can be shown in the list of pages in category A (the backlinks of template A).
Category considerations[edit]
Each page is typically in at least one category. It may be in more, but it may be wise not to put a page in a category and also in a more general category.
Each category, except one top-level category, is typically in at least one higher level category.
The category structure is (ideally) a multi-hierarchy with a single root category. All categories (except root category 1) should be contained in at least one other category, and there should be no cycles (i.e. a category should not contain itself, directly or indirectly). The category structure should reflect a hierarchy of concepts, from the most generic one down to the very specific.
Check the conventions[edit]
Check the conventions in a project and make yourself familiar with the categories in use before assigning pages and subcategories to categories and before creating new categories.
It is not obvious whether a page like Amsterdam should be in category City (a description of a member of the category) or Cities (a description of the category as a set of pages). A convention for using one or the other is useful (e.g. on w:en), to avoid ending up with both, with part of the applicable pages in one, and part in the other.
Putting a category tag on a test page, user page, etc. (also if done indirectly by including a template with a category tag) is considered to pollute the category, while regular links from such pages showing up in "what links here" is considered harmless. Therefore:
- when copying text to such pages, category tags have to be removed; alternatively, convert the category to a link by adding a leading colon after the brackets. For example, "[[:Category:Art]]" is a link to the category, not an assignment to a category.
- when including a template that is in a category, do not use the template feature, but use "subst" or copy-and-paste, and delete the category tags.
Alternatives for overviews[edit]
In addition to the automatic lists of pages and images, an overview of links to pages or images (by means of thumbnails) can be put in the editable part of a category, just like in any page. This used to be widely used in Wikimedia Commons, but now most of such overviews are moved to article namespaces. See also commons:Commons:Images on normal pages or categories:Vote.
Extensions[edit]
Category intersection, union, etc.[edit]
Various MediaWiki extensions allow intersection of categories, union of categories, display of info about the pages in a category, and more:
- Semantic MediaWiki
- Main Page - start page
- Introduction - allows further intersection with sets of pages defined in terms of relations and attributes
- Inline queries - provides relation- and attribute-related info about the selected pages and in-page display on any page of categories the same or another page is in
- DynamicPageList extension can be used to:
- intersection of categories
- generate a list of all those articles (or a random sample)
- show metadata of the articles (popularity, date of last update, ..)
- show one or more chapters of the articles ('transclude' content)
- show parameter values which are passed to the common template
- order articles appropriately
- present the result in a sortable table (e.g.)
- use multi column output
- Forum
- intersection of categories and complements of categories
- provides the time of last edit for each page
They all also allow further restriction to a namespace; some allow also restriction to a union of namespaces, or the complement of a union of namespaces. They all allow the info to be displayed in any page, not just a separate category page.
See also w:Wikipedia:Category intersection.
Category flattening[edit]
Category flattening is displaying also the articles in a category's subcategories, sub-subcategories, etc.
See also m:Category flatten, and Wikimedia bug 1497.
Count[edit]
As described at Help:Magic_words#Other_2, {{PAGESINCATEGORY:Example}} or {{PAGESINCAT:Example}} return the number of articles in Category:Example (including the number of subcategories, not the articles in the subcategories).
Links to other help pages[edit]
- Help contents
- Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
- Versions of this help page (for other languages see further)
- What links here on Meta or from Meta · Wikipedia · MediaWiki
- Reading
- Go · Search · Stop words · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
- Tracking changes
- Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
- Logging in and preferences
- Logging in · Preferences · User style
- Editing
- Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
- Referencing
- Links · URL · Piped links · Interwiki linking · Footnotes
- Style and formatting
- Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · List · Table · Sorting · Colors · Images and file uploads
- Fixing mistakes
- Show preview · Testing · Reverting edits
- Advanced functioning
- Expansion · Template · Advanced templates · Parser function · Parameter default · Variable · System message · Substitution · Array · Calculation · Embed page
- Others
- Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Languages: | English · Deutsch · español · français · עברית · italiano · 日本語 · Nederlands · русский · 中文 |
---|