Category and subcategory
-
The code below shows the subcategories linked to the selected category. And when clicking on the subcategory link it will show the subcategories of that selected subcategory.
And so on. However, he is not showing the posts when he is at the last level of the subcategory.
How do I get this code to bring posts related to the selected subcategory?
For example:
The category “car” has the subcategories “tires” and “parts”. And the “parts” subcategory has the “engine” and “glass” subcategory. And the “engine” category has the post “Engine 1”.
When I click on the category “car” the page needs to show only the subcategories “tires” and “parts”.
When I click on the “parts” subcategory it should show the “engine” and “glass” subcategories
Finally, when I click on the subcategory “engine” it should show posts related to “engine”.
global $cat; $categoriasFilhas = get_categories(‘parent=’ . $cat); foreach($categoriasFilhas as $category) { echo ‘<p>term_id ) . ‘” >’ . $category->name.’</p>’; }
- The topic ‘Category and subcategory’ is closed to new replies.