How to show subcategories in categories else show posts

Your code checks for child categories and shows them if they exist, but you aren’t then going on to process the loop that would ordinarily display the posts in the current category.

You want to extend your code to be of the form:

if ( is_category() ) {

    $this_category = get_category($cat);

    if ( get_category_children( $this_category->cat_ID ) != "" ) {

        // display the list of child categories as you currently do

    } else {

        /* run the standard loop to show the posts using
           whatever loop code your other templates use
        */

    }
}

Leave a Comment