Archive

Archive for the ‘Wordpress’ Category

Empty Wordpress categories don’t show up in the sidebar navigation

May 5th, 2006 tony 6 comments

I’ve been playing with Wordpress this week for a new feature for my Raleigh, NC and ran into this issue. If a category doesn’t have any posts in it, it will not show up in the sidebar navigation. Even worse, if it is a parent category Wordpress will not show the children categories even if they aren’t empty. I dug into the source code and found that the function responsible for retrieving the category list is wp_list_cats() and by default most themes pass no parameters to it. However, it is capable of accepting a large range of settings including one to fix our problem.

In your sidebar.php file replace this:

<?php wp_list_cats(); ?>

with this:

<?php
	$settings = "hide_empty=0";
	wp_list_cats($settings);
?>

Now all of your categories will show up even if they don’t have any posts in them. Unfortunately clicking on those empty categories results in “Sorry, no posts matched your criteria.”. You can change this by adding a category.php and writing your own content for the scenario where the category is empty.

Categories: Wordpress Tags: