How to show 5 top categories in Wordpress

Status
Not open for further replies.

Osiris

Golden Master
Messages
36,817
Location
Kentucky
Source: How to show 5 top categories in Wordpress

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).
 
Status
Not open for further replies.
Back
Top Bottom