How to print only sub-category name
-
Hey!
I’m trying to figure out how to print only sub-category of a given category. There is one parent category, called “Local”. This parent category has six sub-categories, each of them is a city name. Each post is associated with the parent category, Local, and one of the sub-categories.
For example,Post A – Local and City 1
Post B – Local and City 2I want to print out only the sub-category name within the loop. I’ve come across the following code in wordpress forums but it doesn’t help me as it prints out the parent category name as well.
<?php foreach((get_the_category()) as $category) { echo ( $category->cat_name != 'local' ) ? $category->cat_name . ' ' : ''; } ?>
Any help will be greatly appreciated.
Thanks.
- The topic ‘How to print only sub-category name’ is closed to new replies.