Some times you mat need to style posts differently depending on which category they are in. WordPress by default does not add the category to the body class so you need to add this to your themes’ functions.php file or create a plugin for it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php function pn_body_class_add_categories( $classes ) { // Only proceed if we're on a single post page if ( !is_single() ) return $classes; // Get the categories that are assigned to this post $post_categories = get_the_category(); // Loop over each category in the $categories array foreach( $post_categories as $current_category ) { // Add the current category's slug to the $body_classes array $classes[] = 'category-' . $current_category->slug; } // Finally, return the $body_classes array return $classes; } add_filter( 'body_class', 'pn_body_class_add_categories' ); ?> |