1
votes

I'm trying to create the following menu structure from custom taxonomies:

CAT 1
-SubCat1
-SubCat2

CAT 2
CAT 3
CAT 4

What I want to achieve is when I click on a child category (SubCat1 for example) My current navigation structure should stay the same, and bold the current subcat. When I click on another PARENT category, it's subcategories should appear and the the rest of the parent cats only (not all the cats with subcats).

My problems are the following:

I managed the create the child navigation menu when clicking on a parent category, but it only shows the CURRENT and the CHILD LEVEL categories in the menu, without the other main categories using this code:

<?php
$taxonomy     = $tax;
$orderby      = 'name'; 
$show_count   = 1;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$title        = '';
if (get_term_children($term->term_id, $tax) != null) {
$child = $term->term_id;
} else {
$child = '';
}
$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'title_li'     => $title,
  'child_of'     => $child,
  'current_category'   => 0

);
?>
<? if (get_term_children($term->term_id, $tax) != null) { ?>
<h3><?php echo $term->name; ?> Templates</h3>
<? } ?>
<?php 
wp_list_categories( $args ); ?>

The problem is with the above code that when I click on a child category all my parent/subcategories are displayed again.

I want to be able to stay on the same structure when browsing any of the subcategories from one big category with the addition of the bold font face to the subcategory I'm browsing.

If this makes sense to someone please help.

Thanks,

1

1 Answers

0
votes

What I would do is create a custom query to loop through the taxonomy with a parent of 0 then in the loop of displaying them do the get_term_children function. I believe that is the best way to create something like this. This is what I have done in my plugin and it has allowed me to have much more customisation.