Welcome to the Homepage of Senthil Nachimuthu
How to add an alphabetical index to a category in MediaWiki Print E-mail
User Rating: / 4
PoorBest 
Wednesday, 09 July 2008
MediaWiki is a very nice piece of software, and is the software that runs Wikipedia. MediaWiki supports categories that group together similar concepts (or pages) - here's an example that shows the list of microorganisms and other related concepts. However, when the category has too many members, it becomes very hard to navigate. It would be nice to have an alphabetical index at the top so that you can click a specific letter and go to a page that lists all the members starting with that letter. This feature is not built-in in MediaWiki, and a hack to implement this did not work. Here's my simple, elegant solution to create an alphabetical index.

This is what an alphabetical index will look like. If you click a letter in this index, it will take you to a page that contains members (children and subcategories) of that category that start with the letter you clicked. This page tells how to create an alphabetical index for a Category page in MediaWiki. It tells you to edit several PHP files. But the sad part is that it doesn't work, at least with the MediaWiki version that I run -- 1.12.0.

 So, I created my own method to implement this. It's very simple and elegant, and requires only one template. You need not edit a single PHP file. So, the MediaWiki source code is untouched.

Here's what the template looks like:

<span class="plainlinks"><center>
Jump to:
[{{fullurl:{{FULLPAGENAME}} }} All] 
[{{fullurl:{{FULLPAGENAME}}|from=0}} 0-9] 
[{{fullurl:{{FULLPAGENAME}}|from=A}} A]
...
[{{fullurl:{{FULLPAGENAME}}|from=Z}} Z]
</center></span>

 The ellipsis (...) denotes lines for each letter of the alphabet between A and Z. These lines are not shown here to reduce the size of the code listing. Save this template with a name such as Template_Alphabetical_Index. Here's a real world implementation of this template.

Now, go to any category page and insert a call to this template. All you need to do is to insert the following line into the category page at an appropriate location:

{{Template_Alphabetical_Index}}

 Here's a real world example of one such Category page . Note that this category has several thousand members. Navigating it without an alphabetical index (using the "Previous 200" and "Next 200" links) would be impractical. The alphabetical index makes it very easy to navigate this category.

You can view the source of the template and the category page to see how this is done. Of course, it is easy to make this work with multilingual websites. Make one template for each supported language (because not all languages use the English alphabet). In the template inclusion call, include the one with the same language as the user interface.

Voi-la! We have created alphabetical index for the Categories without modifying a single line of PHP source code, and it is very easy to adapt it for Internationalization and Localization.

If this code is useful to you or you have a better suggestion, please let me know

 





Digg!Reddit!Del.icio.us!Google!Live!Slashdot!Netscape!Technorati!StumbleUpon!Spurl!Newsvine!Furl!Blogmarks!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
Last Updated ( Wednesday, 09 July 2008 )
 
Creative Commons License Copyright 2004-2008 Senthil Nachimuthu. Some rights reserved. The original work on this website is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Powered by Joomla