I have a sidebar and I need to list the terms of the 'Category' taxonomy.
So far so good, what I can not do is: When you click on a term, you must list its children terms in a submenu containing a link to the listing of the child's products.
Current code
sidebar.php
<aside class="sidebar col-md-4 col-lg-3">
<div class="caterias-sidebar">
<p class="titulo-cat">CATEGORIA</p>
<?php print_produtos_por_tax('Categoria'); ?>
</div>
</aside>
UPDATED 1.1 - > functions.php
function print_produtos_por_tax($termos){
$taxonomyName = $termos;
$terms = get_terms($taxonomyName,array('parent' => 0));
echo '<ul>';
foreach($terms as $term) {
echo '<ul><li><a class="elementos-cat" href="#'.$term->term_id.'">'.$term->name.'</a>';
$term_children = get_term_children($term->term_id,$taxonomyName);
echo '<li><ul class="ul-submenu">';
foreach($term_children as $term_child_id) {
$term_child = get_term_by('id',$term_child_id,$taxonomyName);
echo '<li id="#'.$term->term_id.'" class="elementos-cat li-submenu" ><a href="' . get_term_link( $term_child->term_id, $taxonomyName ) . '">' . $term_child->name . '</a></li>';
}
echo '</ul>';
}
echo '</ul>';
}
jQuery(".elementos-cat").click(function () {
jQuery(".ul-submenu").slideToggle('slow');
});
You are currently not identifying which Parent has been clicked to show only their children.
It should work like this: When you click Compressor, you should list all product images independent of the Compressor subcategory, but you should open a Compressor submenu containing the list (Compressor type 1, Compressor type 2, Compressor type 3 ...) p>
Site: http://104.131.64.90