Builder CSS: Adding Additional Classes

From IThemes Codex
Revision as of 10:23, July 30, 2013 by Kristen (Talk | contribs)
Jump to: navigation, search

Categories

In Builder (and in many other themes) by default the body class of a single post page does not contain the categories under which the post has been categorized.


Category-body-class.png


If you would like to apply a specific background to all single post pages that belong to say, "Recipes" category then by using the following code "recipes" will be one of the classes that gets applied to body class. Therefore we can target any element on a single post page belonging to "Recipes" category by prepending the CSS selector with "body.recipes".

Add the following before closing PHP tag in child theme's functions.php:

// add category nicenames in body class
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes[] = $category->category_nicename;
return $classes;
}

add_filter('body_class', 'category_id_class');

Source: http://codex.wordpress.org/Function_Reference/body_class#Adding_More_Classes

Note: In Builder, category/categories are present for post class by default.

Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox