"If Category" function, get child category name
-
Hi,
in my website https://thingstodoincalifornia.info/southbay I have Category headers for each post and they show the Parent Category.
Now only for “Events” Category I’d like headers to show the children categories separated by comma.
Here is the code that actually I’m using<?php $just_shown = $last_shown; $last_shown = array(); $output = ''; foreach((get_the_category()) as $category) { $catname = $category->cat_name; if(!in_array($catname,$just_shown)) { $cat = get_category($category->term_id); //new line to show only top level cat name if(!$cat->parent) { $output .= $catname . ' '; } //new if statement } $last_shown[] = $catname; } if($output != '') { echo '<div class="sectioncat">' . $output . '</div>'; } ?>
How to change it and accomplish what I want?
Thanks
- The topic ‘"If Category" function, get child category name’ is closed to new replies.