Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Problem with taxonomy (child vs no child) WordPress

  • SOLVED

I'm struggling with taxonomies. I've created a custom post type ("Products") with taxonomies like this:

- Kitchen Accessories
-- Mixers
-- Juicers
-- Slicers
- Saucepans
- Cutlery

Basically, when I click on Saucepans I'd like to display every items in Saucepans (and exactly the same for Cutlery).
But when I click on Kitchen Accessories, I don't want to display every items, I just want a list like this :
<ul>
<li>Mixers</li>
<li>Juicers</li>
<li>Slicers</li>
</ul>
And now, when I click on Mixers for example, I'd like to display every items in Mixers.

Answers (1)

2011-06-21

John Cotton answers:

The simplest way would be to have a custom template for those terms where you wanted that effect.

So create a file in your theme called taxonomy-kitchen-accessories.php, copy the contents of an existing file to get the basic structure and then replace the loop with your list using, for example [[LINK href="http://codex.wordpress.org/Function_Reference/get_term_children"]]get_term_children[[/LINK]]


Thomas Guillot comments:

Hi John,

Thank you so much, it's working quite well but what should I do if I don't want to create a new file?

Cheers,

Thomas


John Cotton comments:

Well you would have to have some if..else code in one of your other template files. But then the code starts to get messy....

Always best to go with the flow grain of how WordPress works....

JC


Thomas Guillot comments:

Yeah, you're right.

Anyway, thanks for your help.

Cheers,

Thomas