WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Listing Child & Sibling Categories (4 posts)

  1. tommysvr
    Member
    Posted 3 years ago #

    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.

  2. tommysvr
    Member
    Posted 3 years ago #

    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);
    }
    }
    ?>
  3. lindalibinbin
    Member
    Posted 2 years ago #

    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!

  4. tommysvr
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic