One of the most powerful tools in customizing a set of pages via CSS is custom body tags. If you want to customize the look of all of the posts that belong to a certain category, the easiest way to do it is by adding a custom class to the body tag of every post in that category.
I use the Genesis Theme Framework for almost all of the wordpress sites I develop and most of the Genesis Child Themes already have this functionality built in. If you are not using the Genesis Theme Framework, or are using a theme that doesn’t have category body tags included in the Body tag by default, here is the code that you can use to add the category slug as custom body tag to your posts.
This code should be added to your theme’s functions.php file.
/*Add custom body tag for categories*/
add_filter( ‘body_class’, ‘cat_body_class’ );
function cat_body_class( $classes ) {
if (is_single()) {
$category = get_the_category();
$classes[] = ‘category-‘.$category[0]->slug;
}
return $classes;
}
If you are looking for a general tutorial on how to add custom body tags, Studio Press has a great tutorial on it here:
http://my.studiopress.com/snippets/custom-body-class/
Leave a Reply