Get the parent category for single posts
-
Hi
I′m making the brand of my site change it′s color depending on the category it′s showing.
I need to get the parent category for single posts, so that I can tell my css what class to show.
Here is the code:<?php if (is_front_page() ) { $cat = "home"; } elseif (is_category()) { $cat = get_category_parents($cat, FALSE,'',TRUE); } elseif (is_single()) { $cat = get_the_category($cat->parent); $cat = $cat[0]->slug; echo $cat; } ?>
Category pages are working fine, but I can′t make single to work.
Also, I don′t want to type each post ID because it will be a nightmare!Any ideas?
Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Get the parent category for single posts’ is closed to new replies.