views:

41

answers:

2

Hi gurus, I was wondering if anybody know hows to modify the existing category widget to only display the categories within the selected parent category. Example:

If my categories are structured like:

  • Computers
    • Laptops
    • Desktops
    • Software
  • Electronics
    • Cameras
    • Audio/Video

If a somebody is viewing posts in the Computers category I would like the categories widget in the side bar to only display Laptops, Desktops & Software..

Is there a way to get this done? Is anybody familiar of a plugin that maybe do that? Thanks!

+2  A: 

how about using something like this? on a singles page you could add a call from within the single.php page to a new sidebar or an include file...?

ie:

<?php if( is_single() ) { include(TEMPLATEPATH.'/newsidebar.php'); } ?>

newsidebar.php

<ul> 
<?php 
 $catsy = get_the_category();
 $myCat = $catsy->cat_ID;
    wp_list_categories('orderby=id&child_of='.$myCat); 
?>
</ul>

this will show only categories from the currently used category?

ie:

if current category is 5 // Computers then all that will be shown in the list is

* Laptops
* Desktops
* Software
Marty
+1  A: 

Thanks for your help. I was able to get it to work by doing this...

<?php
if (is_category()) {
    $cat = get_query_var('cat');
    $this_category = get_category($cat);
    $this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
    if($this_category !='<li>No categories</li>')
    {
     echo '<h3>Products</h3>'; 
     echo '<ul>'.$this_category.'</ul>'; 
    }
}
?>
Ash