How to echo one category name out of a parent/child relationship
-
Ok, my Blog uses a category structure like that:
Food
– Fruits
— Banana
— Apple
— Pineapple
– Icecram
— Vanilla
— Chocolate
— HazelnutNon-Food
– Paper
– Stonesand so on…
So if I write about a new Vanilla Icecream Creation it belongs to
Food-Icecream-Vanilla
and I only check the Vanilla Box during the post administration
Now, here’s my problem:
If I want to echo the category name inside the loop I use
<?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?>
But in another case I only want to show the second parent category
(Example: Icecream for the Food-Icecream-Vanilla Category Article)
Is there any way to do that… I tried a lot using get_category_parents but I’m not able to solve that problem…
Help please 🙂
- The topic ‘How to echo one category name out of a parent/child relationship’ is closed to new replies.