Lifestyle
 

Help:Category

From Consumer Information

Contents

[edit] How categories work

A category is a software feature of MediaWiki. To avoid confusion with the general term category, it may sometimes be useful to use the term MediaWiki category.

Categories provide automatic indexes, that are useful as table of contents. Together with links and templates they structure a project.

[edit] Putting an item in a category

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]]

This lists the page on the appropriate category page automatically and also provides a link at the bottom of the page to the category page, which is 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 article, although they are typically added to the end of the article to avoid undesirable text display side effects. Category links are displayed in the order they occur in the article, unlike the automatic ordering of lists in the category pages themselves (see below).

Putting an image in a category is equivalent to putting the image page in it.

A category page itself typically has an editable part, containing at least a category tag of a supercategory, see below; if it does not, the link to the category page is treated as a link to a nonexisting page; hence, it is a link to the edit page.

[edit] Subcategories

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:Soccer]].

Then go to the newly created category page and edit it. Add the category tag for the parent category (e.g. [[Category:Sports]]) to the page.

In this example, the Soccer category would then be a subcategory of the Sports category. For a live example see Category:Demo_1 which is a subcategory of Category:Demo.

[edit] Category page

A category page consists of:

  • editable text
  • list of subcategories; how many there are is also displayed; if there are no subcategories the header and count are not shown.
  • list of pages in the category, excluding subcategories and images; the number of items in this list is called the number of articles; if there are none the header is shown anyway, and "There are 0 articles in this category." Template:H:new
  • list of images with thumbnails (how many there are is not counted); the first 20 characters of the image 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 subheaders per letter, it has not even a header itself and visually seems to fall under the header of the previous section "Articles in category ...", even though in counting the articles, images/image pages are not considered articles).

To create a category page, you must 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 from to the category:

[[:Category:Category name]]

Placing the above text on working page will create the link you can use to edit your category page.

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.

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).

Help:Alphabetic order

[edit] Order of the lists; setting sort keys

Each of the three lists is in the order explained above. If you want an item in a list to be positioned in that order, based on 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|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, and, unfortunately, only visible on the edit pages of the members of the category. 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.

The sort key is case sensitive, so a page with the tag [[Category:Foo|Zealand]] is sorted before one with the tag [[Category:Foo|amsterdam]]. This can be inconvenient, requiring a sortkey in projects with case-sensitivity of the first character if one wants the A and the a together, but it may also be used to one's advantage: e.g., it allows sorting of the pages into two groups, one put in the range A-Z and one in a-z, using sortkeys; see e.g. Category:Demo, where the help pages are put separately by using sortkeys with lower-case "h".

To get the order right, be consistent in punctuation and spacing. For example, "A Z" with two blank spaces comes before "A A" with one.

An underscore in a page name is equivalent with, and treated as a blank space. However, an underscore in a sort key is distinct from a blank space.

Note that e.g. Ä comes after Z, unless a sort key is used, see e.g. de:Special:Allpages/Zz and wikisource:Special:Allpages/Zu.

As seen from the ASCII sequence above, forcing items to the beginning or end can be done with a sort key starting with a space or ~, respectively. Another common sort key for the beginning of the list is the asterisk (*).

[edit] Sort key of images

Images without sort key are alphabetized according the full name, including namespace prefix "Image:". Therefore, for images for which a sort key is used, the prefix should also be included, otherwise these images are positioned on the category page before "Image:A" or after "Image:Z". Alternatively, all images can be given a sort key.

Thus a list of images may show a sequence A-I, A-Z, I-Z. One may choose to fix the first and third sequence by adding the prefix to the sort keys, or the second sequence, by putting sort keys without prefix.

Similar remarks apply for other non-main namespaces. However, the category namespace is an exception: the default sort key is without prefix, to avoid listing all subcategories by default under the C. Therefore, explicit sort keys should also be without prefix.

[edit] Grouping of pages by using sortkeys

If e.g. in a list of people sortkeys 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 sortkey "K Einstein, Albert" is used.

[edit] Labels in the list of images

As mentioned above, the first 20 characters of the image name are shown, with dots if that is not the full name. This can be inconvenient, e.g. in commons:Category:William-Adolphe Bouguereau most images have a name starting with "William-Adolphe Bouguereau (1825-1905) -", which are therefore all labeled "William-Adolphe Boug..." (see the last section of the category page).

The full names are only shown in the hover box and the status bar, depending on the browser; in the latter possibly with codes such as "%28" for "(".

Thus, looking up a name in the alphabetic list is cumbersome. It might have been better to start the names with the shorter "Bouguereau, " and then the title of the painting (unless the software will be improved later).

[edit] Alternatives for overviews

An overview of links to pages and of images by means of thumbnails, can be put in the editable part of a category, just like in any page, or be generated in the second, third and fourth part of the category page.

The first gives control on structure and lay-out. For example, in the editable part of commons:Category:William-Adolphe Bouguereau the name of the painter does not have to be repeated, and the full titles of the paintings can be shown.

The second is more convenient for new pages/images: by putting the category tag (which for images can even be done in the upload summary) the overview is automatically updated. Also, the sorting in alphabetic order is automatic in the second case.

A category page may have an overview in the first part, as well as in one or more of the other parts, with the following possibilities:

  • items occur twice, but ordered and structured differently, with different info (including that the fourth section shows the file sizes); when creating/uploading new items, they can be put in the category first, which is a convenient intermediate stage for updating the editable part
  • avoiding duplications

Anyway, a category has the double functionality of allowing extension of the overviews both from the overview page and from the member pages. This convenience makes it easier to build and maintain a complete overview (albeit divided over sections) for the subject concerned.

If the second, third and fourth part of the category page are not used than the category page is much like a page in another namespace. Differences are:

  • the name starts with "Category:"
  • in ordinary links to the category page the name is preceded by a colon
  • Related Changes does not work for the editable part

If a category is growing too large, it is cumbersome to split. When new items need to be added, and they are on a subtopic about which there is still little in the category, this is a good occasion to start a subcategory. Other kinds of overview can be split more easily.

See also commons:Commons:Images on normal pages or categories:Vote.

[edit] Linking to a category

If you want to link to a category without the current page being added to it, you should use the link form [[:Category:foobar]] (where foobar is the category name). Note the extra : before Category.

[edit] Existing categories

You can see currently used categories for each project with Special:Categories, for Wikipedia w:Special:Categories. It produces a list of all categories, including those which contain subcategories or pages, but have no additional text, as opposed to Special:Allpages for the Category namespace (on Meta: [1]), which does not include the latter. In that case a link to the category page shows up as link to a non-existing page that leads to the edit page. Even with preview this does not show the pages etc. in the category; use Cancel or, better, add a supercategory and/or other text, and save, to see the pages in the category.

Navigation is by number in alphabetic order, not by starting letter. For projects with thousands of categories this is cumbersome.

[edit] A category tag in a template; caching problem

If a template contains the code indicating that it is in a category, this does not only put that template in the category, but also the pages that include the template. For example, this page includes Template:Hh and as a result is in Category:English documentation.

The page that contains the template correctly lists the categories to which it belongs. However, adding or deleting a category tag in the template does not add or delete the listings on the category page of pages that use the template, until some edit is made in the page that uses the template.

In other words:

  • lists of categories a page is in, are up-to-date
  • lists of pages in a category are based on the situation just after the last edit of the pages

Since adding or removing a category or template tag is obviously an edit there is only a complication when a page is indirectly added to or deleted from a category, through a change in a template the page uses.

To refresh category pages with respect to the listing of a particular page (adding or deleting the entry), a null edit can be applied to that page: just applying section edit and saving without changes.

[edit] Sort key

A sort key in a category tag in a template applies to the template as well as to the pages that use it, so it is only useful if it is variable. It can depend on a variable (notably PAGENAME), parameter, or the content of a template.

[edit] Categorizing templates themselves

To categorize templates themselves, without the pages that call them, one could consider putting the category tag in the talk page of the template, and an explanation on the category page that the template talk pages listed are meant as categorization of the templates.

Another way of doing this is using the <noinclude> tag. Example:
<noinclude>[[Category:category name]]</noinclude>

Which is more convenient in use depends on whether one wants, from the category page, easy access to the talk page or to the template page, and conversely: whether one wants easy access to the category page from the template talk page or from the template page.

[edit] Excluding templates from categories

Use:
<includeonly>
to keep a template from showing up in a category. Text between
<includeonly>
and
</includeonly>
will be processed and displayed only when the page is being included. The obvious application is:


  • Adding all pages containing a given template to a category


Note that the usual update problems apply -- if you change the categories inside a template, the categories of the referring pages won't be updated until those pages are edited.

[edit] How the Shopping Wiki sorts its pages

The category structure in Shopping Wiki is as follows. Note that one subcategory may belong to several higher categories, so there is no strict tree structure.

  • Products These articles, which will probably make up the bulk of the wiki's content, describe specific makes and models of products, such as the HP-842c inkjet printer or the Crayola 96-pack of crayons. Second-level categories include Electronics and Appliances; deeper categories correspond to product types (see below).

Contents

A category is a software feature of MediaWiki that provides automatic indexes, that are useful as table of contents. Together with links and templates they can structure a project and aid navigation.

Using categories

How can I categorize pages?

Any page can be put in a category by editing the page and adding a link to the category. Just type [[Category:]], and put the name of the category between the colon and the brackets.

[[Category:NAME]]

You can create new categories just by typing a new name. Pages can belong to more than one category, by having multiple category tags on the page.

All categories will appear at the bottom of an article page, in a "Categories" box. Clicking the category name will take you to a Category description page which will list all articles and subcategories contained within that category. You may click "edit" on a category description page to add additional text or images to the top of the page above the subcategory lists, and to place the category in another category.

Please note, category description pages are not designed to carry general content - they do not get counted in article statistics, and will not be found via many Special pages.

How do I create subcategories?

A category becomes a subcategory when you edit the category description page to add a Category tag for a "higher level" category. There is no limit to the number of subcategories a category may contain, or to the number of levels of categories. It is possible (though rarely desirable) to create category "loops".

The root category on most wikis is called Category:Browse. It is good practice to build a complete Category Tree, ensuring that all categories on your wiki have a place as subcategories of Category:Browse or its descendants.

How do I link to a category page?

To create an internal link to a category page without placing the edited page into the category itself, you must put a colon before the word "Category":

[[:Category:NAME]]

Can I redirect a category to another category?

No - attempting to Redirect a category will not work correctly (though it is technically possible). What you can do is add a notice (such as Wikia:Template:Category redirect) to inform users that a different category name should be used. You may then delete the old category once everything has been edited to show the correct category. However, if anyone might unknowingly try to re-create the "wrong" category, the template should remain in place for ever.[1]

Where can I see the currently used categories?

You can see a list of all currently used categories for each Wikia at Special:Categories. This list also displays how many pages are within each category.

You can reach this page by clicking the word "Categories" at the beginning of the box at the bottom of any categorized article, or by clicking "Special pages" in the sidebar.

Extensions

Category Tree

Special:CategoryTree is an alternate way to display the contents of a category. It can be transcluded in other pages. See mw:Extension:CategoryTree for details.

The extension also adds the ability to expand subcategories on a category page, allowing you to see further subcategories.

CategorySelect

CategorySelect (also sometimes referred to as 'Category tagging'), is a Wikia developed extension that allows users to quickly add a category to a page, without going into the edit mode for the page. It adds a small (usually green) button in the category area of the page, that uses AJAX functions to add the category code to the page for you.

Read more at Help:CategorySelect

See also

Notes

  1. See Wikipedia:Template talk:Category redirect for discussion.