I'm trying in vain to show a subcategory, rather than or in addition to a parent category, in my body class so I can add active states for a subnav on a post. The post is inside the press-releases category, but I also have posts in its parent category, news. I need an active state only for press-releases. I'm sure I've gone about this all the wrong way, but being PHP illiterate, this is where I'm at.
Found this at http://codex.wordpress.org/Function_Reference/body_class
// add category nicenames in body and post class
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes[] = $category->category_nicename;
return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
But I can't figure out how to get the subcategory. Anyone?
The site isn't officially public yet but I can post a link later if necessary to show context.