• Resolved zedesino

    (@zedesino)


    I was trying to show subcategories in sidebar when i’m on parent category. i did not find code so i tweak one for subpages and want to share with you. So code showing subcategories when you are on parent category:

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

    this code also showing children categories if you click on some of them. you can see in action here. so “avialable works” and “biography” are children categories of parent “artist name category”

    cheers!

Viewing 1 replies (of 1 total)
  • hi zedesino,

    it looks like this is exactly what i want to do (i.e. only show parent categories in sidebar until they are clicked, which then shows child categories under their parent).

    where exactly do i put this code? in the stylesheet? in the sidebar.php? also, which pieces of code are editable (where do i plug in the category names)? sorry. i’m new to php programming.

    thanks much!

Viewing 1 replies (of 1 total)
  • The topic ‘Showing children categories in sidebar when you are click on parent category’ is closed to new replies.