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

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

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:
  1. May 20th, 2006 at 13:18 | #1

    To find out how to solve that “Sorry, no posts matched your criteria” problem, visit this url:

    http://wordpress.org/support/topic/33805?replies=8#post-378560

  2. January 6th, 2007 at 09:35 | #2

    Hi Tony. I googled here, searching an answer to the same question. A shame empty parents don’t show their children. I tried your tweak but it doesn’t seem to have had any effect. I have about 20 categories, but only four are showing now. Looking at your categories, I think you still have the same problem as well. Do you know of any other solutions to this problem?

  3. March 19th, 2007 at 15:33 | #3

    Hello,

    In search of this solution, made a little tweak.

    If the above line is placed in the place of the original, all categories will be shown empty or not.

    Enjoy!

  4. Joshua Isaac
    March 19th, 2007 at 15:35 | #4

    Sorry, it didn’t post.

    wp_list_categories(‘hide_empty=0′);

    This will fix it!

  5. April 4th, 2007 at 14:36 | #5

    The last comment works! I was looking for a way to take out “/category/” in my url’s. I cant figure it out.

  6. Fatih
    September 29th, 2008 at 15:25 | #6

    Is there any chance to sort categories in wordpress?