Support » Fixing WordPress » Show subcategories only for selected category

  • Is it possible to show subcategoris only for the category which is being viewed. I have a lot of categories and all of them have their subcategories, but I don’t want to show them on main page. I want to show subcategories only for that category which is viewed by visitor. Is it possible

Viewing 15 replies - 1 through 15 (of 20 total)
  • i am suffering from the same problem, would appreciate some advice!

    Please help somebody,

    The example of what I want to do in on Yahoo Answers… When you select one category there are only it’s subcategories in sidebar. How can I do the same with wordpress?

    I need the same – is there a plugin for this? Notice this is marked as resolved but I don’t see a resolution…

    Can I add Adsense to my profile ? Sorry I’m new here.
    Ken Stepp

    Similar (now closed) question here:

    Any ideas?

    I am also interesed in this. This must be a future in wordpress ! They lack at the categry part in rest they rock



    This might be what you’re after:

    if (is_category()) {
    $this_category = get_category($cat);
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->category_parent."&echo=0"); else
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->cat_ID."&echo=0");
    if ($this_category) { ?>
    <?php echo $this_category; ?>
    <?php } ?>

    This is the reference page, where they have a simpler example. This doesn’t list sub-categories when on a particular sub-category page though. However, in the comments, there is a snippet which is similar to the above.

    This works for me, although I’d like to re-write it so that it doesn’t show on the front page, nor prints out “No categories” when there are no sub-categories.. but it’s a start and might help someone out there.



    <?php wp_list_categories('orderby=id&show_count=1
    &use_desc_for_title=0&child_of='.$cat); ?>


    The example of what I want to do in on Yahoo Answers… When you select one category there are only it’s subcategories in sidebar. How can I do the same with wordpress?

    I am also eager to know a solution to this problem.

    Someone help please.



    I can’t believe my eyes! I’ve been searching on google for an hour or two and this questions here does not seem to be answered – even collapsing categories should be a basic functionality.

    After such a long search I guess WordPress can not produce this behaviour with the base install and so has to be extended – has anyone found a better solution than

    Rgds, Henning



    *er*, and this

    but for the moment I can’t get one or the other do what I want (they should by description but both fail due to misc errors). We’ll see.

    Karl19 –

    if (is_category()) {
    $this_category = get_category($cat);
    $this_category = wp_list_categories(‘orderby=id&title_li=&child_of=’.$this_category->category_parent.”&echo=0″); else
    $this_category = wp_list_categories(‘orderby=id&title_li=&child_of=’.$this_category->cat_ID.”&echo=0″);
    if ($this_category) { ?>

      <?php echo $this_category; ?>

    <?php } ?>

    Thank you so much! This works fine for me, I’ve been looking all over for something like this.

    Does anyone have an idea on how to tweak that code to display the Category Descriptions instead of the Name?

    Haven’t fully explored this but the documentation for wp_list_categories is at

    About 3/4 down the page their is the description of the Parameter:

    (boolean) Sets whether a category’s description is inserted into the title attribute of the links created (i.e. Category Description” href=”…). The default is true (category descriptions will be inserted). Valid values:

    * 1 (true) – default
    * 0 (false)

    Is this what you’re looking for?


    Thanks for taking an interest in this!

    The “use_desc_for_title” is not really what I’m looking for. What it does is it outputs the Category Description as the title of the link, i.e. the text that shows up in a little box when you hover the link.
    What I’m looking for is a way to output the description instead of the name of the Category as the actual link to that specific category.

    MichaelH here on the forum has helped me out a bit with this.
    His code does the trick I’m looking for, but only while in a Top Category, it returns nothing while in a sub-category.

    $cat = get_query_var('cat');
    if ($categories) {
     foreach($categories as $term) {
       echo '<a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View %s" ), $term->description ) . '" ' . '>' . $term->description.'</a>';

    Any ideas are highly appreciated!
    Thanks again!

    I guess no one has a solution for this yet?

    I’ll keep my eyes peeled 🙂


Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Show subcategories only for selected category’ is closed to new replies.