WordPress.org

Support

Support » Themes and Templates » Display Sub Categories on single.php

Display Sub Categories on single.php

  • Hi, I’m using the below code from http://wordpress.org/support/topic/84230?replies=14 to display subcategories of just the category I’m on. However, if I click on a post in that category, the subcategories disappear, I assume because $cat no longer exists? Any thoughts how to acheive this?

    <?php /* Display sub-categories, you have to add manually the parent catgeory ID concerned */ $this_category = get_category($cat); if (($this_category->cat_ID == 1) or ($this_category->cat_ID == 4) or ($this_category->cat_ID == 5)) { ?>
    <h4><?php echo $this_category->cat_name; ?>Sub-Categories:</h4>
    <ul class="sub-categories">
    <?php wp_list_cats('sort_column=ID&sort_order=asc&list=1&optioncount=0&hide_empty=0&use_desc_for_title=1&children=0&child_of='.$cat.'&Categories=0&hierarchical=1'); ?>
    </ul>
    
    <?php } elseif (($this_category->category_parent == 1) or ($this_category->category_parent == 4) or ($this_category->category_parent == 5)) { ?>
    
    <h4><?php echo(get_category_parents($this_category->category_parent, FALSE, '', FALSE)); ?>Sub-Categories:</h4>
    <ul class="sub-categories">
    <?php wp_list_cats('sort_column=ID&sort_order=asc&list=1&optioncount=0&hide_empty=0&use_desc_for_title=1&children=0&child_of='.$this_category->category_parent.'&Categories=0&hierarchical=1'); ?>
    </ul>
    <?php } /* end of Display sub-categories */ ?>

    Cheers,
    Iain

Viewing 1 replies (of 1 total)
  • Hope this example helps you… Subcategory highlighting on single pages, is not working indeed…

    $this_cat = get_category($cat);
    if( is_page('some-page') || is_category('some-cat') || <strong>$this_cat->category_parent == 1</strong> ) echo $etc['subcats']
Viewing 1 replies (of 1 total)
  • The topic ‘Display Sub Categories on single.php’ is closed to new replies.