Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress widget how to only display sub-categories based on selected Parent Category?

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

like image 469
Ash Avatar asked Oct 24 '10 17:10

Ash


People also ask

How do I display all subcategories from a specific category in WooCommerce?

Click on Appearance > Customize. Then go to WooCommerce > Product Catalog. Select “show subcategories” from Category Display. Click on Save Changes.

How do I show subcategories on a category page in WordPress?

Activate the plugin through the 'Plugins' screen in WordPress. On the 'Widgets' sub-menu of 'Appearance' you will find a new widget type called 'Sub Category'. Add one or more of these to your themes widget display areas. For each widget you add, decide what and how you'd like it to display.

Can you have subcategories in WordPress?

In WordPress, your posts can be organized into different categories and tags. You can even create subcategories for further organization. Using categories and subcategories can help your readers find the content they're most interested in and improve your website's SEO rankings.

How do I find the specific category of a widget in WordPress?

Simply go to the Appearance » Widgets page and add the 'Latest Posts' block to your sidebar. By default, the block will show your most recent posts. You edit the block settings and scroll to the 'Sorting & Filtering' section. From here, you can choose the category that you want to display posts from.


1 Answers

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
like image 143
Marty Avatar answered Oct 06 '22 10:10

Marty