Wordpress widget how to show only subcategories based on the selected parent category?

I was interested to know if anyone knows how to change the widget of an existing category to display only the categories in the selected parent category. Example:

If my categories are structured as follows:

  • Computers
    • Laptops
    • Desktop computers
    • Software
  • Electronics
    • Cameras
    • Audio Video

If someone is viewing messages in the Computers category, I would like category widgets on the sidebar to display only Laptops, Desktop Computers, and Software.

Is there any way to do this? Does anyone know a plugin that can do this? Thanks!

+4
source share
3 answers

Thank you for your help. I was able to make it 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>'; } } ?> 
+3
source

how about using something like that? on the singles page, can you add a call from single.php to a new sidebar or include ... file?

those.:

 <?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> 

Will only categories from the current category be displayed?

t

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

 * Laptops * Desktops * Software 
+5
source

1) Show only subcategories:

 <?php // check if the page is viewed is a category page. if (is_category()) { $cur_cat = get_query_var('cat'); if ($cur_cat) { $new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat . '&depth=1&title_li=&&show_count=1&hide_empty=0'); echo '<ul>' . $new_cats . '</ul>'; } } ?> 

2) Show all main categories:

 <?php wp_list_categories('depth=1&title_li=&exclude=1&show_count=1&hide_empty=0'); ?> 

3) Show all categories + Subcategories, such as the tree menu:

 Use FoCal plugin. 

4) also review this code:

 http://wpworks.wordpress.com/2011/01/13/displaying-categories-and-subcategories-tree-on-wordpress/ 
0
source

All Articles