Help talk:Categories

Sub-categorising
Should anyone add information here on how to put one category under another (subcategory)?
 * This was done a while back (but since the question was asked) --HappyDog 16:35, 27 August 2007 (UTC)
 * The explanation about how to add subcategories is unclear. I inserted comments directly into the article highlighting the ambiguities. 66.220.233.173 19:33, 27 September 2010 (UTC)

Hiding categories
How does one hide category display?


 * You can hide the category links at the bottom of a page using CSS (e.g. ).  --HappyDog 01:36, 28 June 2007 (UTC)

But how does one hide an article (or something like a template) from being included within a category?

Hiding categories from category pages
I am using MediaWiki 1.15.1 and would like to hide some categories even from category pages, something which is impossible right now, AFAIK. Reason: I use categories as dynamic table of contents and the categories I want to hide are shortcut redirects, then are just maintenance.

Is it possible? Is it in the queue line for implementation? FYI, here's the ticket I started at MediaZilla.

Thanks!

David Latapie 08:59, 15 November 2009 (UTC)

Hiding the Main Page category
Is it possible to hide the category on the main page, but not on other pages? Regards, Guido den Broeder 10:31, 19 July 2011 (UTC)
 * Found it myself. The css should contain: body.Page-main_Page #catlinks { display : none } Guido den Broeder 11:24, 19 July 2011 (UTC)

Intro
I think it's important to define what a Category is. It could be placed before the help section where it explains how to add a category, as a noob might not know what the Category does. Just a suggestion. --Hawkwynd 12:23, 24 August 2007 (UTC)


 * Thanks. It's a wiki, so feel free to add this kind of text yourself!  In the meantime, I've added a rough-and-ready intro.  Please tweak it if you feel the need. --HappyDog 16:35, 27 August 2007 (UTC)

second independent category system
I want to introduce a second category system in my wiki or let me call it an "advanced Tag-System". The idea is to tag every page with some words as links - similiar to the categorie syntax. When I then click this words, I want to see a page with the content of "what links here". Besides this I want to keep the standard category tree. Have anyone has an idea, how to realize this? --87.162.127.221 13:43, 14 October 2007 (UTC)
 * Try Semantic MediaWiki? --141.14.26.125 08:21, 19 February 2008 (UTC)

Language
Could someone please add a guide on how one can change the name "Category" into something localised in other languages? --David Munch 14:41, 12 April 2008 (UTC)
 * I would think that would be the "MediaWiki:Categories" page of your wiki; accessible via "Special:Allmessages". --Lance May 12:49, 12 June 2008 (UTC)

Sorting question...
In an interesting display, I have managed to thoroughly confuse myself with categories. When sorting using the "" suggestion, I've gotten my templates to exhibit the appropriate behavior. The category is "Templates", and the namespace is the default "Template". This works perfectly. However, when I tried this with another category (originally the same name in category as in namespace), they simply sort by the namespace. I've since renamed the category and left the namespace the same. It still sorts by the namespace. The only difference in the two situations that I can see now is that the problematic pages are also tied to another category. Do categories not sort if the pages are attached to more than one? --Lance May 18:04, 11 June 2008 (UTC)
 * Okay, so just in case there are others out there who may have a similar issue. Any level of pride does not prohibit me from saying that the issue above was not only my fault, it was my complete ignorance of the product's features. Essentially, I had expected that namespaces would be created just as any other page; through usage. Granted, this would not be feasible in situations like Wikipedia, so I can see why it is not that way. So that is what the delta was between the two situations; one was a real namespace and had a, the other was not and did not. However, in the interest of possibly lending a hand to anyone else running across this issue, please see Manual:$wgExtraNamespaces before just creating "Something:Like_this", as it will not become a namespace without setting it up ahead of time.

in pages categorized via templates
I'm facing a problem to which I haven't yet found any answer or solution: in a wiki I collaborate to, we have a kind of pages that are categorized in two different ways: When I decided for DEFAULTSORT in place of the old procedure of manually inserting a sort key in each category tag (and for the templates, by passing the sort key as parameter), I discovered that DEFAULTSORT only works for the categories local to the page, but not for the ones inserted by the templates. Is there a way to change this behavior and force all categories to follow DEFAULTSORT? Even a tweak in the wiki code would be welcome! Thanks --Capmo 21:49, 12 October 2008 (UTC)
 * 1) via directly receiving category tags (say,  ), and
 * 2) by receiving templates that categorize the page indirectly (i.e.: templates   that insert the page in categories  ).


 * should apply also to categories included via templates. However, keep in mind that it's the default sort key: any explicitly specified sort key will override it.  —Ilmari Karonen 22:58, 14 December 2008 (UTC)


 * Thanks for your reply, you were right: some of the templates had a sortkey code defined in them that was preventing DEFAULTSORT from working properly. It was something like this:  . When no sortkey was passed as parameter, the "magic word" PAGENAME would become active and override DEFAULTSORT. When I removed all that and left only    everything worked fine! Capmo 04:50, 15 December 2008 (UTC)

Changing items listed per category
I know I can place the following global variable into LocalSettings.php

$wgCategoryPagingLimit = 600;

To alter all categories in a Wiki.

But someone said that the latest MediaWiki now allows this to be done on a per category basis?

If so, does anyone know the magic word I add into a category page to do this?

I can't find it listed.

--Stuart Halliday 12:10, 20 January 2009 (UTC)

Sort by more than one character
What if I want to sort by year? If I do it will be listed on the :Category:Year page under "2", right along with articles in I would rather have it be listed under "2009," so that "2008" shows up separately.


 * I had the same desire, with the addition that I wanted it to be controllable. So I wanted to be able to either provide a specific sort or else I wanted one to be automatically found (based on the first character). I searched around, but couldn't find anything that worked for me. What I ended up doing was just modifying the library code (bad; I know.)
 * In ../includes/CategoryPage.php I modified the "addPage" function to be;

/** function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang; $titletext = $wgContLang->convert( $title->getPrefixedText ); $this->articles[] = $isRedirect ? ' ' . $this->getSkin->makeKnownLinkObj( $title, $titletext ). ' '		: $this->getSkin->makeSizeLinkObj( $pageLength, $title, $titletext ); if($wgContLang->firstChar( $sortkey )=="("){		$this->articles_start_char[] = $wgContLang->convert( trim($sortkey,"") );	}else{		$this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );	} }
 * Add a miscellaneous page
 * This change allows a sort key to be wrapped in parentheis, in which case the key is fully displayed in the category list. For example, the following would list the page under a key of "2009" instead of just "2".


 * I'm sure there's a much better way to acheive this same result. Modifying the base library code is never something that should be done and the code above is far from "good" (for example, a key of "(2009 (June))" would result in "2009 (June" instead of "2009 (June)" as would be desired.) But it gets the job done (or does so enough for my needs.) Hopefully someone with more knowledge/experience could offer a more agreeable solution...? --Dlhdesign 00:49, 22 September 2009 (UTC)
 * Here a modified version of the above "if"-statement that let's you sort the articles within the "headlines":

if($wgContLang->firstChar( $sortkey )=="("){			$closepar=strpos($sortkey, ")"); $sortkey=substr($sortkey, 0, $closepar); $this->articles_start_char[] = $wgContLang->convert( trim($sortkey,"("));
 * This let's you add text behind the closing parenthesis, by which the articles are sorted within their groups.
 * e.g.: comes before  in the 2009 section.
 * The recommended use would be, to give the pagetitle, so that the articles are in alphabetical order.
 * Sidcom 17:55, 21 February 2010 (UTC)
 * The above solution worked for me as of MediaWiki version 1.17.0. Thanks! Just wanted to pop in and let people know that it still works. For additional clarity, here's the code in full:

function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang; $titletext = $wgContLang->convert( $title->getPrefixedText ); $this->articles[] = $isRedirect ? ' ' . $this->getSkin->makeKnownLinkObj( $title, $titletext ). ' '     : $this->getSkin->makeSizeLinkObj( $pageLength, $title, $titletext ); if($wgContLang->firstChar( $sortkey )=="("){     $closepar=strpos($sortkey, ")"); $sortkey=substr($sortkey, 0, $closepar); $this->articles_start_char[] = $wgContLang->convert( trim($sortkey,"("));   }else{      $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );    }  }
 * --Cameronmalek 02:12, 13 September 2011 (UTC)

And what if I want a subcategory to be listed in a parent category by a different name? For example, I have Category 2009 as a subcategory of Articles, and instead of 2009 showing up on the Category:Articles page under subcategory header 2 I want it to be listed under subcategory header Year.
 * The same solution as above could be done for the sub-category listings. Modify the "getSubcategorySortChar" function on the same page to return a different result when the key is surrounded by parenthesis and then modify the category definition on the sub-category page to include the parenthesis. for example, in the 2009 category page, include the following:


 * --Dlhdesign 00:56, 22 September 2009 (UTC)

And what if I want to list the same article in the same category with multiple keys? If I do: It will only appear once on the :Category:Author page, under "A". I would like the Author page in this case to list a header "Aleph" and all pages with him listed as an author, and a separate header "Gammow" with the same.


 * I know it doesn't work to put the same category twice, even with different sort keys. In fact, there's a cleanup project that's identifying articles like that, so that it can be corrected.
 * One thing you can do (and I don't know if this fits what you had in mind) is put categories on redirect pages. Two examples are the English Wikipedia pages for Nickolas Ashford and Valerie Simpson, which both redirect to Ashford & Simpson. The redirect pages for their individual names have default sort keys for their individual names, and include categories that apply to them as individuals. One category listed on both pages is "Living people", so they'd appear separately in that category. Does that help? --Auntof6 23:14, 5 June 2009 (UTC)
 * The SQL table which stores the category links (aptly named "categorylinks") has a unique key on cl_from and cl_to, which means that a single page can only link to a particular category once. This is likely "enforced" in the parse code by using a unique key in an array or something (I didn't look for it in the code, so am not sure on that bit.) So in your example above, the "Gammow" key overwrites/replaces the "Aleph" key before it even gets saved to the DB.
 * In theory, you could further modify the "getPage" and "getSubcategorySortChar" to look for a splittable list and then have it add a unique "page" for each split item. For example, you could provide a key of "Aleph,Gammow" which would then split the key on the comma and list the page under both the "A" and "G" keys. Or (extending the above), you could provide a key of "(Aleph),(Gammow)" and it could list it under the full keys. You would likely need to decide how to deal with the key counts, since the visible number of links would be different than the true counts. I'd personally just change the text to list them as "unique pages" or the like, but there are other options there as well...
 * The final modification would then be to adjust the parser so that duplicate sort keys on the same category link result in a joined session key. This joined key would then be stored in the DB as if it had been passed in above, making your above syntax correct. --Dlhdesign 01:24, 22 September 2009 (UTC)
 * Any way the library could be interrupted through extensions? Seems it would be much better to make an extension to do this than hacking the source file that handles this.Goldbishop 01:51, 29 July 2010 (UTC)
 * Just created Extension:CategorySortHeaders. Requires MediaWiki 1.19 though (on 1.17 and 1.18 can work with a much less scary patch). Bawolff 07:47, 25 June 2011 (UTC)


 * If you still want to use a hack in the code, I improved to accept inner parentheis (the outer-most delimits the sortkey).

/** * Add a miscellaneous page */ function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang;

$link = Linker::link( $title ); if ( $isRedirect ) { // This seems kind of pointless given 'mw-redirect' class, // but keeping for back-compatiability with user css. $link = ' '. $link. ' ';	}	$this->articles[] = $link;

// *** HACK *** // /* ---OLD--- * / $this->articles_start_char[] = $wgContLang->convert( 		$this->collation->getFirstLetter( $sortkey ) ); /* ---OLD--- */ /* ---NEW--- */ $match = array; if(preg_match('/\((.+)\)/', $sortkey, $match)) { $this->articles_start_char[] = $wgContLang->convert( $this->collation->getSortKey( $match[1] ) ); }else{ $this->articles_start_char[] = $wgContLang->convert( $this->collation->getFirstLetter( $sortkey ) ); }	/* ---NEW--- */ }
 * 177.17.154.145 22:35, 24 January 2012 (UTC)

Sort numbers by more than one character

 * I read the above "solutions" about sorting but I think I'm having a different problem.
 * e.g. I have two categories, one is called "Test 90" one is "Test 100". Those two categories belong to the category "Numbers". There they are sorted this way: T --> first "Test 100" and THEN "Test 90". So MediaWiki seems to look from character to character (and in this case numbers) which makes the sorting very wrong. Does anyone have a solution for this? This would be awesome! --SmartK 14:41, 23 August 2010 (UTC)
 * General technique that is beneficial is to use same number of digits (e.g. Test 100, Test 090), then it forces the computer to index correctly. Similarly, putting dates in a YYYYMMDD format will always group by the larger bucket, ie year, then month, then day). hope that helps.

Sorting Categories by date
By default a category page display the related items according to the letters Is it possible to change it to dates, years and months
 * The answer is no. Sorting is by alphabetical order of the sort key, always. One can do a manual approximation of a sort by "dates, years and months", providing a sort key which, when sorted alphabetically, yields the desired result. For example, articles named "A1", "A2" and "A3" categorized, respectively, with:


 * A1:
 * A2:
 * A3:


 * would be listed under Category:C in the following order:


 * A3
 * A2
 * A1


 * However, they would all be grouped under heading "2", because all the sort keys start be "2". If one of the dates is "1999 01 03", that page would be grouped under the separate heading "1" because it starts by "1". To ensure all pages were sorted under one single heading, you need to start all sort keys by the same caracter, so "*20100903", "*20100902", "*20100901" and "*19990103" would be sorted in one single groupd under heading "*" because they all start by "*". All the sort keys have to be created and maintained by users manually. Hamilton Abreu 00:27, 13 October 2010 (UTC)
 * cough dpl. (I only mention it since that was the original use case for the extension. Wikinews uses that extension extensively to give pseudo-category listings by date) You can also sort by date the category was added to the page using the api if you don't mind the non-pretty interface. Bawolff

How to remove a category
- Hello ! I cannot find it. I know that there are other rules than on the pages but is there a possibility to remove category that is no longer needed ?
 * - Simply remove all occurrences of a category on wiki pages and the category will automatically disappear. -- Satri 12:53, 18 October 2010 (UTC)
 * If the category page had text on it it still appears in Special pages -> Categories -> Unused categories. 132.177.122.112 19:59, 15 February 2011 (UTC)

Category aliases / multi-language categories / grouping categories
- We have a wiki in multiple languages. We want some categories to be grouped together, such as a "City" category (English) and a "Ville" category (French). At the moment, the two categories are distinct. Does anyone knows how we could automatically "group" these two categories to act as a single one? (ideally without having to add the two categories to a page) Thanks. -- Satri 13:00, 18 October 2010 (UTC)


 * - won't a redirect work for this? -- Oo.et.oO 18:48, 28 November 2010 (UTC)


 * - No, a redirect from one category page to another category page will not add the categorized pages to the second target category, so this doesn't work. Thanks for trying to find a solution. -- Satri 21:03, 1 December 2010 (UTC)

Space a sort key using DEFAULTSORT
It appears that using a single space as sort key doesn't work using the DEFAULTSORT variable, i.e. simply gets ignored. Is there some way to work around this? __Meco 22:34, 18 October 2010 (UTC)
 * Use (In case your wondering, &amp;#32; is space as space is character number 32 in ascii/unicode). I'm not sure if defaultsort should really be trimming spaces like that. This could potentially be a bug. Bawolff 03:53, 19 October 2010 (UTC)

Categories not appearing
I'm attempting to add categories to several pages on the Venture Bros. Wiki and for some reason they are not appearing. I'm typing them in correctly and everything, does anyone know how to fix this? Uncle Tyrone

Let users choose categories in the drop down manner
I want to allow my users to choose the category in the dropdown fashion in the article, is it possible to achieve this through some extension, if so, what extension?


 * semantic media wiki w/ semantic forms
 * --Oo.et.oO 03:27, 10 December 2010 (UTC)

Can I put multiple categories in one tag?
This is how it is right now: can i put all categories in one tag? Something like that:


 * No (unless there's some extension floating around somewhere for this). —Emufarmers(T 18:39, 17 December 2010 (UTC)


 * See now Extension:ArrayExtension. Cavila (MW 1.17, MySQL 5.1.57, Php 5.2.17) 18:25, 7 August 2011 (UTC)

How do I hide a specific category?
At the end of the article I have list of categories om my article. I want to hide specifically one category from my guests how do I go about doing this? If it is possible that is.


 * Please refer to Help:Categories. Hamilton Abreu 14:11, 23 December 2010 (UTC)

I can´t access my categories
Hallo, after upgrating with SMWHalo i can´t navigate over categoties. Eachtime then I am clicking a category i recive thei error: Notice: Undefined offset: 1 in C:\aaaaaa\wiki\includes\GlobalFunctions.php on line 1369

Fatal error: Cannot redeclare class SMWWikiPageValue in C:\aaaaaa\wiki\extensions\SemanticMediaWiki\includes\SMW_DV_WikiPage.php on line 378 why? Thanks, 87.139.141.76 08:20, 7 February 2011 (UTC)

Don't show "Category:"-Namespace in Subcategory Section
Does anyone know, how to make MW not show "Category:foo", but only "foo" in the subcategories section? I do have a working 1.15.1 Version, that doesn't show it and a 1.17 that does. I can't find any documented configuration setting that documents this and I couldn't find a relevant difference in the settings so far. I do however believe to remember, that this was a feature ;) of the 1.15.1 Version only - but how do I reproduce it then? --Sidcom 20:57, 16 June 2011 (UTC)

Sub Category
Hi. I was wondering about sub-categories. Is it possible to have several sub-categories named the same? For example if I have two game categories (I run a gaming site) where one is called World of Warcraft and the other is called Runes of Magic, and then I want a sub-category in both of them called "Class Guides".

So it would look like Category:World of Warcraft -> (sub)category:Class Guides and at the same time have Category:Runes of Magic -> (sub)Category:Class Guides.
 * No, but you can call them Category:World of Warcraft:Class Guides and Category:Runes of Magic:Class Guides respectively. Regards, Guido den Broeder 23:25, 24 July 2011 (UTC)

Query Categories
Is there any way to make a category page that can perform something like a basic SQL query on various categories? For example, I have a Wiki with pages for various books, movies, albums, etc. Each page has a category for what form of media it is (book/movie/etc.), what year it came out in, and the genres and themes it covers. Is there a way to make a category page that shows me just movies from the 1980s that feature time travel? Thanks! --TheAlmightyGuru 21:42, 17 August 2011 (UTC)

Displaying entries on category page.
I have about 150 entries that are a person's name. I've flagged all of these for a specific category and use their last name as a sort key. This works great for keeping all the Smith's under the "S" subheading.

However, is there a way to indicate how each entry should be displayed on the category page?

For instance, I'd like "John Smith" to appear under the "S" category, but listed as "Smith, John".

Thanks!

Sort in reverse order
There are articles A and B in the category C. They are sorted according to ASCII - A then B. As I can sort the articles in one category in reverse order? B then A. Or not 1,2,3 but 3,2,1.
 * Maybe there's something in Category:Category extensions that allows you to do that, but not anything I'm aware of. It would make sense if for instance, your category contains a lot of dates and you want to start with the most recent one. You could consider Extension:Semantic MediaWiki, with which you can build queries and choose a suitable output format, including MediaWiki categories in reverse order. Cavila MW 1.17, MySQL 5.5.16, Php 5.3.8 21:52, 23 November 2011 (UTC)

Add a page to a variable category
Is it possible to use a template to add a page to a category? Using the following code on a template called by a page does not work, even if the variable is set: