Support » Fixing WordPress » Click on category goes to list of child categories

  • Resolved toddtwining


    This is a simple thing in CMS platforms but with WP I can’t get it to happen. My client will be adding alot of categories and sub-categories, and needs to have it when a user to clicks on a category link, they are brought to a page with a list of the child categories. This will allow a simple “drill down” for users. also, There are 3-4 child levels for each category. I cannot create php staements for each as that solution would take forever I would think I could use the structure within WP already to simply accomplish this, but I have not found any solutions.
    Any Help is appreciated

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael


    Forum Moderator

    if a user clicks on a category, that leads him to a category archive page, done with category.php

    right at the start of that template, you can check if the current catgory has a parent or children, and dependant on that, you can show the list of sub-categories or posts.

    this might be useful:
    $the_active_cat_ID = get_query_var('cat');

    Thanks for the prompt reply. I am not much of a coder so I am finding the dots a little too far apart to connect. It seems I need to add code to category.php
    I see the examples of arguments, but I am not sure how to use the code to get my sub category names to display in place of sub cat posts.
    I appreciate any further “dumbed down” guidance.
    Thanks again.



    Forum Moderator

    what theme are you using right now?

    to allow the suggestions to match your existing structure, please paste the full code of category.php into a pastebin and post the link to it here – ( )

    category.php is-



    Forum Moderator

    this section is new:

    //show a list of direct child (sub) categories if available//
    	if( $list = wp_list_categories('echo=0&title_li=&show_option_none=&depth=1&child_of='.get_query_var('cat')) ) {
    		echo '<h3 class="sub-categories-title">Sub Categories List</h3>';
    		echo '<ul class="sub-categories">' . $list . '</ul>';
    //tweak the query to show only posts direct in the current category//
    	global $wp_query;
    	$args = array_merge( $wp_query->query_vars, array( 'category__in' => array(get_query_var('cat')) ) );
    	query_posts( $args );

    the first part checks if there are direct children (sub-categories) of the current category, then output the list.

    the second part changes the query to show only posts which are in the direct category (normally the category archive will also show posts which are in sub categories of the current category).

    new introduced css classes for better formatting:


    Boy did that work perfect!
    Thank you so much for awsome support!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Click on category goes to list of child categories’ is closed to new replies.