How to show empty categories in Wordpress using the default category widget

This is a hack, but a simple one.  Surprisingly enough, Wordpress 2.3 doesn’t have an option in the default category widget to show empty categories.  Personally I prefer to only show categories that have posts, but here’s a really simple way to do it.

If you are not using widgets, use this to call the list category function with the proper parameters in sidebar.php or whatever file you’re using to display the categories:

$args = “hide_empty=0″;
wp_list_cats($args);

If you are using widgets, it’s just as easy,  open /includes/widgets.php and search for “$cat_args” (should be around line 627 or so).  Change this line:

$cat_args = “orderby=name&show_count={$c}&hierarchical={$h}”;

to

$cat_args = “hide_empty=0&orderby=name&show_count={$c}&hierarchical={$h}”;

I’m sure there is a simple way to change the properties of the default category widget to  allow you to set that parameter through the widget UI, but this works great and doesn’t cause any problem using widgets.

Related posts:

  1. How to Show Empty Categories in Wordpress 2.7
  2. How to Exclude Category Posts from your Wordpress Homepage
  3. How to manually change your Wordpress theme


3 Responses to “How to show empty categories in Wordpress using the default category widget”

  • Andrew Says:

    Okay, so I go that part working for me, the remaining problem is that empty category links all point to the 404 error page. I haven’t found any way to selectively make the empty categories plain text (not links) or give a category specific error/empty message to people who click on the empty category

  • Jason Says:

    Hi Andrew, you can actually create a category template page for each category that will allow you to customize the text. Make a copy of the category.php page and name it category-ID.php where “ID” is the actual category ID. That page would be displayed instead of the Wordpress 404 page. More instructions about category templates are on the Wordpress site: http://codex.wordpress.org/Category_Templates

  • How to Show Empty Categories in Wordpress 2.7 | jasonlittle.ca Says:

    [...] an update of how to show empty categories using the default Category widget in Wordpress 2.7.  My previous post was for pre-2.7 Wordpress sites, this update is still simple; actually it’s easier since Wordpress switched to using an array [...]

Leave a Reply