0

I have typical parent and child categories setup as follows:

  • Food
    • potatoes
    • corn
    • beats
  • Sports
    • soccer
    • football
    • hockey

etc.

In my index.php template I'd like to list the categories of the specific post. The problem is, when I use the_category() it lists the parent categories twice. I'm using the following code:

<php echo '<dt>', the_category(', ', 'multiple'), '</dt>', "\n"; ?>

And it prints out:

Food:corn, Food, Food:potatoes

I believe it is listing the child category "corn" as "Food: corn" followed by the parent category "Food" just as "Food." Is there a way to exclude the parent categories?

The way I'd like it to read is:

Food:corn, Food:potatoes

Thank you.

  • Have you tagged the post in Food, Food:Corn, and Food:potatoes? Try categorizing it in Food:corn and Food:potatoes only. – Jonnybojangles Feb 17 '11 at 0:05
  • Jonny, that's it. Thanks! If you make your comment an answer, I'll approve it. – simon6167 Feb 17 '11 at 0:26
1

Have you tagged the post in Food, Food:Corn, and Food:potatoes? Try categorizing it in Food:corn and Food:potatoes only.

I do not believe that there is a means to exclude categories from the_category() function. You will have to use another function to create a custom query to do so.

Try some of these.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.