hi,
i have an issue and have looked high and low for the answer but to no avail. i have many wordpress sites and love wordpress but on this occassion i am stumped.
basically i have a site with many child categories of parent categories
i.e. category 1 --> category 1.1
category 1.2
etc
i want all the child categories, post pages etc to have the same parent categories sytle. i.e i everything that is in category 1 to have exactly the same backgound header etc.
i managed this for post and pages by using the following in functons.php:
}
add_filter('body_class','add_category_to_single');
function add_category_to_single($classes, $class) {
if (is_single() ) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
echo $category->cat_name . ' ';
// add category slug to the $classes array
$classes[] = 'category-'.$category->slug;
}
}
// return the $classes array
return $classes;
}
this was great. for each post it showed every category that the body was in, incluuding for example 'category-1' which i could then style using CSS.
however this was obviously not applicable for my child categories and they do not show in body class the parent category that i have assigned them.
i would be very grateful if someone could help me to get a potential conditional format via functions.php so that for example category 1--> category 1.1 will show in body class it's parent category so it can be styled by my parent cateorgy css.
many thanks in advance for any help. i really have spent hours searching this and to no avail for categories so it is not for the want of trying or an easy way out to ask, i am just stumped!!!!
many thanks
Nick
The blog I need help with is test.keystagehistory.co.uk.