WordPress is a great piece of software, and allows more than you’d think to be done with simple coding. I bet that a lot of people out there would look for a plugin to do this, but your top five categories can very easily be shown using a WordPress template tag, just a half a line of code.
The tag we need is called “wp_list_categories()” and by default it lists all your categories in alphabetical order. All we need to do is add some arguments to it to modify the default values and we’re done! We need to limit the number of items shown to five, we also want to show the post counts in the categories and we want to order the list by the post count, in descending order.
The “number” argument actually has no default value. The reason for this is that it limits the SQL query directly, so there is no need for it by default. We can add it though to impose a limit, so our first argument will be “number=5″. We also want to show the post counts, so we use “show_count=1″ to enable this (show_count=0 is the default).
We also want to order the list by the post count, so we use “orderby=count” to achieve this. By default lists are sorted ascending, meaning that the lowest post count would show up first. To make the list descending, we can use “order=DESC”.
I also use one last argument in there, which is “title_li=”. This sets the title of the list to be nothing, by default the list is presented with a title. I like to hard code my titles for a few reasons, but feel free to change this as you like. So here is the complete code I used, one simple line to do a seemingly hard task, enjoy
<?php wp_list_categories(‘number=5&show_count=1&orderby=count&order=DESC&title_li=’) ?>
If you’d like to read some similar articles, take a look at Scriptastique, a blog all about web development and coding, with great tips on CSS, HTML, PHP, MySQL and Javascript and tutorials and screencasts coming soon! You can follow us on our RSS feed, or Twitter where we’re posting 3-4 short tips daily now!
Related Articles:
Exclude Categories From WordPress FeedsWordPress: Customer Headers For Categories
Subscribe To Categories, Authors Or Tags In WordPress
Show message count of all folders in Thunderbird
Add Thumbnails To Your WordPress Blog

Great. Is there a way to show most viewed categories?
Thanks.
Hi Lance!
No, not this easily, WordPress doesn’t have a tracking system installed by default to do this. I think Popularity Contest by Alex King can display most viewed categories, but I’m not sure. If you are handy at coding this is not all that difficult to code in though.
If you need some help let me know,
Daniel
Nice. Some time ago I tried to deal with similar prob in WP. Thanks for sharing this tip.
This is exactly what I was looking for – thanks for the tip!
nice, really nice!
how i get pages into pages in word press and how to make nambers for the psotes in the home page i wich u can help me thanx
may i know where to add the code ??? please help me …
thanks in advance ….