Showing children categories in sidebar when you are click on parent category
-
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)
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.