• Resolved tommysvr

    (@tommysvr)


    Hi,

    Got an interesting one here. These are my categories:

    – Topics of Interest
    – – Citizenship
    – – – Lectures
    – – – Articles
    – – – Podcasts

    – – Society
    – – – Lectures
    – – – Articles
    – – – Podcasts

    etc.

    What I would like: When you are on the Citizenship category page, it lists the three child categories. But the complication comes here: when you click on Lecturers, Articles or Podcasts, I want it to still list those three categories (now the siblings).

    Does anyone have an idea on how might be the best way to achieve this? Many thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tommysvr

    (@tommysvr)

    Nevermind! This does the job exactly:

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

    Hi, i don’t know anything about coding, but I need the exact same thing. Can you please tell me where to insert this code? Also, I’m using suffusion theme, would the Sayontan please help me on this please too? Thank you so much!

    Thread Starter tommysvr

    (@tommysvr)

    Hi,

    It’s pretty straight forward – you could put that pretty much anywhere in the theme. The most likely spot would be in sidebar.php

    I haven’t been able to look through that theme much and have never used it, so I’m not sure about the styling, but you could possibly just add this to the sidebar and see how it shows up:

    <!--widget start -->
    	<div id="categories" class="dbx-box suf-widget widget_categories">
    	  <div class="dbx-content">
    	  <h3 class="dbx-handle <?php echo $suf_sidebar_header;?>"><?php _e('Categories', 'suffusion'); ?></h3>
    	    <?php
    if (is_category()) {
    $this_category = get_category($cat);
    if (get_category_children($this_category->cat_ID) != "") {
    wp_list_categories('hide_empty=0&title_li=&child_of=' . $this_category->cat_ID);
    }
    else {
    $parent = $this_category->category_parent;
    wp_list_categories('hide_empty=0&title_li=&child_of=' . $parent);
    }
    }
    ?>
    	  </div>
    	</div>
    	<!--widget end -->

    Hope that helps somewhat.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Listing Child & Sibling Categories’ is closed to new replies.