• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • Presentations and Interviews
    • on GitHub →
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • WordPress Plugins

Stephanie Leary

Writer, Front End Developer, former WordPress consultant

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

Category (or taxonomy) drill-down pages

June 14, 2016 Stephanie Leary 2 Comments

Diagram of three category pages. On the first two, for categories that have children, only a list of linked child categories is shown. The third, for a category with no more children, shows the usual post loop.

WordPress category archives are very inclusive. They list all the posts in a category, including all the child categories. This is also true for all other hierarchical taxonomies.

If you have a deep hierarchy, it might make more sense to have your users drill down until they reach a term that doesn’t have children, and then they’d see the list of posts.

Diagram of three category pages. On the first two, for categories that have children, only a list of linked child categories is shown. The third, for a category with no more children, shows the usual post loop.
Categories with children will show a list of those children. No posts are shown until we reach a category that has no children.

To do this, we can add some code to the taxonomy archive template to check whether the current term has children, and if it does, display a list of child terms instead of the Loop.

Here’s a category.php file (or an taxonomy.php file) that displays intermediate terms as links instead of listing posts.

https://gist.github.com/sillybean/1ade0061e5f1a2b1b3fd

WordPress categories, content strategy, taxonomies, themes

This is an excerpt from Content Strategy for WordPress.My latest books are Content Strategy for WordPress (2015) and WordPress for Web Developers (2013). Sign up to be notified when I have a new book for you.

Reader Interactions

Comments

  1. Steve Axworthy says

    September 21, 2017 at 1:16 pm

    Hello Stephanie,
    Been searching for a solution to a problem I am having and found this post… I am not great with coding for wp but have some coding background so please type slow ;)

    I am creating a store for tshirts I list on Amazon. I have a page that displays the children of category 15 with a custom template… some of those categories have children… right now, when you click on one of them it takes you to a page with a custom theme that displays all the tshirts (posts) in that category… my goal is, that when you click on a category that has childern categories, instead of getting the page with posts I want a page with the children categories… so you can drill down through the children..
    Something like this:

    Loop
    If Cat has children
    Link to page that lists children categories
    Else
    Link to page that displays posts in that category
    End else
    End loop

    Here is the code of the current page that shows the categories:

    <?php get_sidebar('top');

    echo '';

    $args = array(
    'parent' => 15,
    'hide_empty' => 0
    );

    foreach( get_categories( $args ) as $category) {

    if ( $category->term_id 15) { // hides 't-shirt category

    echo '';
    echo '';

    echo 'slug . '">';

    echo do_shortcode(sprintf('[wp_custom_image_category term_id="%s"]',$category->term_id));
    echo ''. $category->cat_name . '
    ';
    echo '';
    echo '';
    echo '';

    $index++;

    if ($index % 8 == 0) {

    echo '';

    }

    }

    }
    echo '';
    get_sidebar('bottom'); ?>

    I have been messing with your code and am getting nowhere…

    Any assistance would be GREATLY appreciated!
    Thanks,
    Steve

    Reply
  2. Steve Axworthy says

    September 21, 2017 at 1:25 pm

    that code didnt display right even with the code tags.. I can send you the file if you want to see it.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2025 Stephanie Leary · Contact