/***************************************************************
* Function body_class_section
* Add the top level page to the body class for coloured sections
***************************************************************/
add_filter('body_class','body_class_section');
function body_class_section($classes) {
global $wpdb, $post;
if (is_page()) {
if ($post->post_parent) {
$parent = end(get_post_ancestors($current_page_id));
} else {
$parent = $post->ID;
}
$post_data = get_post($parent, ARRAY_A);
$classes[] = 'section-' . $post_data['post_name'];
}
return $classes;
}
This filter adds a unique body class based on the highest level parent of the current page. I use this for sites that have specific colours or layouts for each section of the site. It works best with sites based around pages. CSS examples:
.section-about { background: red; }
.section-portfolio { background: blue; }
Your theme must also make use of the body_class function.