Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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
    
Done, Thanks simon6167. –  Jonnybojangles Feb 17 '11 at 1:58

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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