We have 3 levels of categories. I thought that this plugin would show the subcategories of the immediate category (even if it wasn’t the “Top” level). It seems to only show the second level. In other words when the cats are structured:
Top Level
– Second Level
–Third Level
And the “second” level is selected, then the plugin still only shows the “second” level of categories, not the “third”.
Is this the expected behavior?
https://www.ads-software.com/plugins/list-sub-categories-lsc/
]]>Hi.
This is exactly the plugin I was looking for. However, is there a way to make this plugin show custom categories instead of the original post categories. To explain a little better, I run a classifieds ads page and I was ordering if there is a way to make is how the subcategories for the ad categories instead of post categories. I appreciate any help/
https://www.ads-software.com/extend/plugins/list-sub-categories-lsc/
]]>Is it possible to show this widget not only on category page but on articles too?
That way it would list subcategories of the category that post is filed under.
https://www.ads-software.com/extend/plugins/list-sub-categories-lsc/
]]>there’re many sub-categories, so help me display sub-categories as dropdown
https://www.ads-software.com/extend/plugins/list-sub-categories-lsc/
]]>Hi!
Its plugin-defoult (list-sub-categories-lsc) function for get subcategories:
global $cat;
// Get ancestors/parents (if there is any).
$ancestors = get_ancestors( $cat, 'category' );
// Get the first ancestor/parent (if there is one).
$ancestor = $ancestors[0];
// If we found an ancestor/parent (then we must be in a sub category).
if($ancestor){
// Get "children" to "ancestor/parent" (here we use $ancestor, since we are in a sub category).
// Note: $ancestor is the main category id of the sub category id.
foreach(get_categories("parent=$ancestor") as $category){
// echo categories.
echo 'term_id ) .'">'.$category->cat_name.'
';
}
}
// If we did NOT find an ancestor (then we must be in a main category).
if(!$ancestor){
// Get "children" to "ancestor/parent" (here we use $cat, since we are in a main category).
foreach(get_categories("parent=$cat") as $category){
// echo cateogries.
echo 'term_id ) .'">'.$category->cat_name.'
';
}
}
all work, but here:
1. not ID for curent category
2. there was no link to the parent category
I am not a programmer, but after week reading I get a work function, which I arranged for:
global $cat;
// Get ancestors/parents (if there is any).
$ancestors = get_ancestors( $cat, 'category' );
// Get the first ancestor/parent (if there is one).
$ancestor = $ancestors[0];
$child_cat = get_categories("parent=$cat");
// If we found an ancestor/parent (then we must be in a sub category).
if($ancestor){
echo '<h1>'.get_cat_name($ancestor).'</h1>';
?>
<nav>
// If we did NOT find an ancestor (then we must be in a main category).
if(!$ancestor && $child_cat){
?>
<h1><?php printf( single_cat_title( '', false ) . '' );?></h1>
<nav>
';
}
?>
Function is used in the template “Category” and can provide additional navigation for subcategories. like Apple ??
But it remains no certainty with respect to the code. All the same I do not have to do with PHP or other programming languages??, this is my first attempt.
In the end, I raised two questions:
1. My code is correct with respect to PHP and WP?
2. How well chosen the function with respect to performance?
Thanks.
https://www.ads-software.com/extend/plugins/list-sub-categories-lsc/
]]>