Help:Category Ⅱ【中半】Category p…
Categories and templates
A template can be used to add pages to a category, 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.
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. 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.
To add the template itself to the category page as well, omit the "includeonly" tags. To add the template to a category without categorizing pages on which the template is transcluded, place the category declaration between <noinclude>...</noinclude> tags, or add it to the template documentation page between <includeonly></includeonly> (the latter allows recategorizing the template without editing it, which is helpful if it is protected, or so complicated that mere mortals hesitate to touch it).
Parser functions can be used to make the transcluded categories, or the sort key used in them, dependent on other variables, notably PAGENAME.
- Passing a category name as a parameter
- <includeonly>[[Category:{{{cat|default}}}]]</includeonly> or <includeonly>{{{cat|[[Category: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=" (equal to nothing) disables putting the page in any category.
- Excluding non-article pages
- <includeonly>{{#if:{{NAMESPACE}} | | [[Category:XXX]]}}</includeonly>
the variable NAMESPACE is null for mainspace articles. For any space other than mainspace, this ParserFunction will produce an empty string, but for regular articles this will include the article in Category:XXX.
On Wikipedia it is not recommended that templates be used to populate ordinary content categories of articles. See Categorization using templates in the categorization guideline.
Categorizing redirect pages
Redirect pages can be categorized. The category tag must be placed after the redirect link. On a category page, redirects are listed in italics.
For conventions on the categorization of redirects in Wikipedia, see Wikipedia:Categorizing redirects.
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 {{category redirect}}
. 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 {{category redirect}}
template. See Wikipedia:Categories for discussion#Redirecting categories for more on category redirects.
Searching for articles in categories
For more details on this topic, see Help:Searching § Syntax.
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.
An "OR" can be added to join the contents of one category with the contents of another. For example, enter
-
incategory:"Suspension bridges" OR incategory:"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.
"Related Changes" with categories
For a category, the "Related Changes" feature, applied to the corresponding category page, lists recent changes to the pages currently listed as belonging to that category. Where those pages are subcategories or image pages, only changes to their editable parts are listed.
Notice that "Related Changes" does not list recent changes to pages linked from the editable part of the category page (as it would normally, with a non-category page). (If a workaround is required for this, the links in question could be placed in a template and transcluded onto the category page.)
As usual (unlike with watchlists) recent changes to corresponding talk pages are not shown under "Related Changes". Pages you are watching are bolded on the list (this can be helpful for finding which pages in a given category you have on your watchlist).
"Related Changes" can be used to find pages which have recently been added to a category (unless they were added through modification of a template; then "What links here" should be used with the template). However it is not possible to detect deletions from a category in this way (since once pages have been removed from a category, their edits no longer show up in Related Changes). Another way of finding recent additions is to use an API query; see Retrieving category information below. There is an external tool to watch additions and removals from categories. CategoryWatchlistBot is another external tool to watch category membership changes.
The DynamicPageList (third-party) extension provides a list of last edits to the pages in a category, or optionally, just the list of pages; the simpler DynamicPageList (Wikimedia) is installed on Meta, Wikinews, Wikibooks and Wikiversity; the extension mw:Extension:DPLforum is installed on Wikia.