If "this" category has children, show them other wise show parent
-
Hi Could anybody help me solve this little dilemma.
I want to list post category, but if the post is in category 3, then list the children of that cat. Check my code out below.
<? $categories = get_the_category(); $creative_field = array(); $location = array(); $auktion = array(); foreach ($categories as $cat) { if ($cat->parent == 3) { //Formgivare $creative_field[] = '<a>cat_ID).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>'; } else if($cat->parent == 1){ //Samlare $location[] = '<a>cat_ID).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>'; } else if ($cat->parent == 16){ //Auktion och alla andra $auktion[] = '<a>cat_ID).'" title="'.$cat->cat_name.'">'.$cat->cat_name.'</a>'; } } if(!empty($creative_field)){ print "". implode(", ",$creative_field); } if(!empty($location)){ print "". implode(", ",$location); } if(!empty($auktion)){ print "". implode(", ",$auktion); } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘If "this" category has children, show them other wise show parent’ is closed to new replies.