Quickly Add Category Totals to Your Sidebar
Most WordPress themes include a category list in the sidebar (take a look at the first sidebar on this site and you’ll quickly know what I mean). The category summary allows a visitor to quickly see all of the subjects you have blogged about on your site. If any topic catches their eye, they can click on the topic and easily see all of the related posts. Unfortunately, in the case of most WordPress themes, visitors don’t know exactly “how many” posts you’ve written on a specific topic until they click on the link. Some themes have added a parenthetical post total next to each topic. Take a look at Fuzzy Future to see a great example of these category totals. I think these totals are a great idea and I wanted to add them to the theme used at my other site Brothers In Blog. The adjustment was very easy and here’s how I did it.
Add “show_count” to “wp_list-categories” to Display the Total Number of Posts for a Specific Category
Most themes display a list of categories in the sidebar.php file. Some themes have more than one sidebar type file so you may have to make these edits more than once:
- Log in as admin to your WordPress powered site
- Select Presentation from the menu bar
- Select Theme Editor from the Presentation sub menu
- Find and select the sidebar.php file in the listing of “theme files” on the right hand side of the screen
- Scroll through this file and locate wp_list_categories() or wp_list_cats()
Note: wp_list_cats() is a deprecated template tag, I suggest you change this tag to its replacement tag wp_list_categories()
- In the parenthesis of this tag enter show_count=1. By default, show_count is set to “0″ which means “false” — don’t display count. Setting the value to “1″ is the same as saying “true” or simply “yes, show the category count.”
- Enclose the setting in single quotes and your updated tag appears as follows: wp_list_categories(’show_count=1′)
- Press the Update File button to save your changes.
- View your site to review and confirm the changes.
NOTE: Don’t forget to surround “show_count=1″ with single quotes inside the parenthesis. If you don’t, you’ll get an error when you view your site.
A quick and easy WordPress theme adjustment that adds, in my opinion, great value with minimal effort.
For more information about WordPress template tags, take a look at the reference page back the WordPress site.
Share, Bookmark, or Email this post
If you liked this post, subscribe to TechTraction's RSS feed or TechTraction's email feed
Filed under: How-To & Tech Tips

How timely! I was thinking about this a couple of days ago.
Thanks for the post, Bret.
I love it when that happens. FYI: Tomorrow I’ve got a similar post coming out for adding archive totals to the sidebar. Pretty much the same approach but the reason for doing so is slightly different.
Thanks for the comment David.
You’re very welcome, Bret.
Personally, I removed my archive list from my site because I can’t imagine too many people search for an article by the month in which it was published. I know I don’t. Do you do this?
I still display the by month archives listed in my sidebar. You do, however, imply a very good question: how much value is there in the by month listing in the sidebar? The answer — probably very little and yet here it is, still on my site. I think you’ve given me an idea for a short post for tomorrow.
Check back tomorrow and I’ll have a post with a poll regarding the value of the archive section. Tell some other folks about it and let’s see if we can get generate some good discussion on this question. Thanks
[...] « TechTraction home page « Quickly Add Category Totals to Your Sidebar [...]
[...] Monday (6/25/07) I posted a short article describing how to add category totals to the category list displayed in your WordPress theme’s sidebar . Adding these totals was easy and a real [...]