|Note: When you edit this page, you agree to release your contribution under the CC0. See Public Domain Help Pages for more info.
Categories, a software feature of MediaWiki, provide automatic indexes that are useful as tables of contents.
You can categorize pages and files by adding one or more Category tags to the content text. These tags create links at the bottom of the page that take you to the list of all pages in that category, which makes it easy to browse related articles.
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:Help". If you open the category 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 the Unicode sort order.
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]]
A new category 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 Category:Contents on Wikipedia.
For a complete list of all categories which have at least one page, see Special:Categories.
For a complete list of all created/edited categories, including the ones that don't have any pages, see Special:Allpages/Category: (note the colon at the end).
Adding a page to a category
To add a page or uploaded file to a category, simply edit the page and add the following text (where Name is the name of the category you want to add it to).
Any number of Category tags may be added to the page and the page will be listed in all of them. Category tags, along with interwiki language links placed in the sidebar, are usually added at the very bottom of the page for the convenience of other editors.
On a categorized page, categories are displayed in the Categories: box strictly in the order they appear in the wikitext.
(At least in MediaWiki 1.18.2) if a category is a subcategory of more than one parent, both hierarchies will be listed, but the tagged category will be stripped off all but one of these. This creates the potential for what appear to be duplicate entries if a category with multiple parents and one of its parents are both tagged on a page. For example suppose Maryanne is a subcategory of both Mary and Anne. If a page tags categories Maryanne and Anne then the Category breadcrumbs will show
Anne Anne Mary -> Maryanne
"Anne" appears to be duplicated, but what is meant is
Anne Anne -> Maryanne Mary -> Maryanne
This is a bug, and has been reported in phab:T35614.
By default, a page is sorted within a category under the first letter of its name — without the namespace.
Also, MediaWiki groups accented characters separately from their unaccented version, so pages starting by À, Á, Ä, will be listed under separate headings, instead of under heading A.
(If you have shell access, these defaults can be changed using
A sort key specifies under which letter heading, and where in the category list, the page will appear. You can add a sort key by placing it inside the tag after a pipe character. For example, the tag below will add the page under heading "S".
Whether or not sort keys are case-sensitive depends on your configuration settings. The order of the sections within a category follows the Unicode sort order. The sort key does not change the page title displayed in the category.
Spaces and other characters are perfectly valid.
See Help:Sorting for further information on category sorting.
Creating a category page
Categories exist even if their page has not been created, but these categories are isolated from others and serve little purpose for organization or navigation.
A category is created by creating a page in the Category: namespace. A category page can be created the same way as other wiki pages (see Help:Starting a new page); just add "
Category:" before the page title.
To avoid extra work, try searching within your wiki before creating a new category. The list of all categories can be found in "Special pages" in the "tools" box of the sidebar.
Managing the category hierarchy
Categories may belong to other categories in a hierarchy. Since category pages are much like any other page, a Category tag may be added to the bottom of a category page.
It is a good idea to organize all categories into a hierarchy with a single top level category. The category structure can take the form of a tree with separate branches, but more often will have a graph structure. Generally, there should be a contiguous chain of parent-child links between each category and the top level category.
The categories that a page is in are normally listed at the bottom of the page. In MediaWiki 1.13+, a category can be hidden from this list by adding the magic word "
__HIDDENCAT__" to the category page.
Users can choose to see hidden categories in a separate "Hidden categories" list, by checking "Show hidden categories" in the "Appearance" section of Special:Preferences.
Hidden categories are automatically added to Category:Hidden categories.
This category is specified in the system message MediaWiki:Hidden-category-category.
Linking to a category
To create a link to a category, use a leading colon before the category name (without this colon, the current page would be added to the category):
To change the link text, write the text inside the link tag after a pipe:
[[:Category:Help|Help category]]→ Help category
Redirect pages that redirect to categories must also use the colon, otherwise they will be added to the category instead of redirecting.
Categories and templates (transcluded pages)
If you add
[[Category:Cats]] inside a template (a transcluded page), both the template and pages which transclude this template will be categorized as Cats.
- If you want only the template to be categorized, you should ensure to write category marker inside
- If you want only the pages which uses the template to be categorized, but not the template itself, you should ensure to write category marker inside
Due to caching issues, editing categories applied through templates may take a while to be visible everywhere.
You can perform a null edit on a page to update immediately its categories.
Redirecting a category
Like normal wiki pages, category pages can be redirected to other normal or category pages. However, this is not recommended, as pages categorized in redirected categories do not get categorized in the target category (phab:T5311). Some Wikimedia sites use a "category redirect" template to mark redirected categories, allowing manual or automated cleanup of pages categorized there.
Certain syntax issues, such as a broken image link, or too many expensive parser functions, can cause a page to be added to a tracking category. See Help:Tracking categories for details.
Renaming a category
If you move a category, since redirect will not work for categorizing, all category tags will be wrong, so you have to fix them.