About a week ago I decided I was unhappy with the archives plugin I was using to display our archives, so I decided to build a custom archives page. This archives page is fairly basic in that it displays the categories and archives side-by-side, then all the posts below it. This way people can use Ctrl+F to quickly find posts they are looking for.
After getting the page built, I realized all of the “child” categories I use for the WordPress Hacks theme was causing some problems, so I decided to remove them from the display. After all, these posts can also be found in their parent category.
If you are displaying your categories somewhere and would like to remove the children, here is the code you’ll need (for WordPress 2.5+):
<?php wp_list_categories('title_li=&depth=1&show_count=1') ?>
The depth=1 is the important one for the purpose of this hack as it is what tells WordPress not to display more than your parent categories. By default, it is of course set to depth=0 (shows all categories). If you are wondering what other options you have, here is what the WordPress Codex lists for the depth parameter:
- 0 – All Categories and child Categories (Default).
- -1 – All Categories displayed in flat (no indent) form (overrides hierarchical).
- 1 – Show only top level Categories.
- n – Value of n (some number) specifies the depth (or level) to descend in displaying Categories.