I have a vertical menu using the superfish script that shows categories in a custom ‘productcategory’ taxonomy. This menu has multiple levels, and is hierarchical.At the bottom of each branch of the tree we have the end category which represents a range of products, which the client does not want to show in this menu.
I am using this code to display it:
<ul class="frontcatlist sf-menu">
<?php
$a = array(
'title_li' => '',
'taxonomy' => 'productcategory',
'depth' => 2
);
wp_list_categories( $a );
?>
</ul>
This is what I currently have in terms of what is showing and what isnt. left being the main categories, and each line being 1 step down to its children:
Those in the red are the categories that are not shown in the menu,
This is not what my client needs however. While I could produce a menu that fits the requirements using the native WordPress 3 menus, that would require manual intervention, intervention that is undesirable, both from a usability perspective, and from the clients wishes.
Since some main categories have subcategories that should be shown and some dont, the depth parameter will not suffice. Instead this is what I need, with the top level categories always showing:
Im not sure how to do this, and the only clue I have is a custom walker class to output custom html, during which I might be able to filter out the ones I dont want ( any categories with a parent that has no children). But I could not see any sufficient examples or articles on the subject, and I’d rather not loose the classes and markup wordpress provides
If anybody has any thoughts, or knows of tutorials forum posts or articles of use, I’d much appreciate it =)
I’ve made some progress based on walker classes but havent gotten ti working quite as needed because wordpress doesnt appear to handle the root nodes of the taxonomy tree in the same way as the child ones.
As a result, it prunes the end menu items, but if the parent of that node is a root level node, it prunes the node and leaves an empty ul element behind,
<ul></ul>
. The code that fixes this issue on child nodes does not work for a root node, resulting in the whole structure flattening with no submenusA temporary workaround is to remove them via the following jquery snippet: