On my WooCommerce website, I have the following Product categories:
• Clothing
- Tee shirts
- Jeans
- Shirts
• Food
- Bread
- Cheese
- Butter
On the category page for “Butter” I would like to show the name of the parent category and the sibling categories of the category “Butter”. This would look like this:
<h2>Food</h2>
<ul>
<li>Bread</li>
<li>Butter</li>
<li>Cheese</li>
</ul>
Similarly, the category page for Jeans should show:
<h2>Clothing</h2>
<ul>
<li>Jeans</li>
<li>Shirts</li>
<li>Tee Shirts</li>
</ul>
How would I achieve this?
Just a first guess, but I think you could grab the category from the query vars, get the term object, and use the term’s parent ID to create a list of terms:
if
wp_list_categories()
doesn’t quite output what you’d want, you can always useget_terms()
and run your ownforeach()
loop.