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.

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Follow Kyle on Twitter @KyleEslick!

  1. kamran says:

    thanks for ur great site
    would u please describe completely how to make the archive page from begining?
    i appricate it

  2. wp codex gives us all we need to know about wordpress, thanks for writing this guide post

  3. M.Farouk says:

    Wow Really nice hack I was like you Kyle having the same problem with my theme now I think it is fixed

  4. Jenyum says:

    I am having a bit of a different but related problem. I’d like to display a list of posts from whatever category my user is browsing, including child categories. Right now it just displays the parent category.

    Here is a link:

    As you can see, it’s the “burgers” category, which is a child of the “eat” category, however the “eat” list is what displays using this code:


    $myposts = get_posts(“numberposts=20&category=$cat_ID”);

    <a href=””>

    I tried using your example but setting the depth to “2” – didn’t seem to have any effect, or maybe I put the code in the wrong place.

    I would be very grateful if you had any advice as to how to get this to work.

Trackbacks/Pingbacks »

  1. Editors Choice » Displaying WordPress categories says:
  2. TECHFLAPS - Waves of Technology | 10 Extremely Useful Wordpress Hacks says:
  3. All Killer WordPress Websites are Built Around These Concepts | Wordpress News and Resources says:
  4. Four Foundational Fundamentals for Website Success « SMELL WHAT I AM THINKING says:
  5. Four Foundational Fundamentals for Website Success :: Tim Engle Design says:
  6. All Killer WordPress Websites are Built Around These Concepts | WebDino.net says: