WordPress.org

Ready to get started?Download WordPress

Forums

Display Sub Categories on single.php (2 posts)

  1. iporter
    Member
    Posted 6 years ago #

    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

  2. n37
    Member
    Posted 6 years ago #

    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']

Topic Closed

This topic has been closed to new replies.

About this Topic