0
I have a sidebar and need to list the taxonomy terms 'Category'.
So far so good, what I can’t do is: By clicking on a term, you should list his children’s terms in a submenu containing a link to the product listing of that child’s.
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');
});
Currently not identifying which Father was clicked to show only his children.
It should work like this: When clicking on Compressor, you should list all product images independent of the subcategory of the Compressor, but you should open a Compressor submenu containing the list (Compressor Type 1, Compressor Type 2, Compressor Type 3...)
Website: http://104.131.64.90
Don’t use the snippet Javascript to format PHP code. And see also: http://meta.pt.stackoverflow.com/questions/297/quando-se-deve-coloca-o-nome-da-linguagem-no-t%C3%Adtulo
– Maniero
Let me get this straight. In this page for example: "http://104.131.64.90/categoria/compressor/" the sidebar would have to show the "children" of compressors?
– Jonathan Célio
I’ll leave a hint for anyone who doesn’t know about it. From the excerpt of your code it looks like you are doing a function for every thing on your site. Take care! A site like this has several pages with different functions. To do this use Object Orientation, you create a consistent and human code. Links: Introduction to OOP - Devmedia and A little about classes - Slideshare
– Jonathan Célio
Please publish the solution in response form. And if I explain what you’ve done to solve it will help anyone looking for the same thing and ends up here.
– brasofilo
If you want to publish your reply on your behalf, let me know and I’ll delete mine that I put in wiki mode. The site is Questions & Answers, solutions should not be posted within the question. Thank you.
– brasofilo