Display only post sub-categories
-
Hey!
I’m trying to print out only sub-categories of each post on category archive of my website. The category structure I have is similar to the following
Parent Category A
Sub-category A.1
Sub-category A.2
Sub-category A.3Let’s say a post is filed under Parent Category A and Sub-category A.1 and Sub-category A.3. When the archive of Parent Category A is viewed, this post is shown there too. Now, I would like to print only the sub-categories of this post Sub-category A.1 and Sub-category A.3 after the excerpt of the post. The position doesn’t matter as I can fix that later.
Anyone could please guide me how I can print out the sub-categories? Any help is much appreciated.
Thanks.
Btw, I’m using the following code to print out only parent category of posts. Maybe I can edit and somehow use it for the purpose above? Any idea?
<?php $category = get_the_category(); $parent = get_cat_name($category[0]->category_parent); if (!empty($parent)) {echo ''. $parent; } else { echo ''. $category[0]->cat_name; } ?>
- The topic ‘Display only post sub-categories’ is closed to new replies.