Add a subsection class to Drupal page body for theming Views and other parts of a site that can be defined by parts of the path
I had wanted to add the name of the view with its display to the body classes (Views apparently provides everything but that combination, and not all browsers we need to support deal with matching on two sibling classes). Looked in Zen for how to do it first though and as a consequence saw a way to add new sub-section body class with the first two parts of each URL.
This goes in your zen subtheme's implementation of preprocess page:
<?php
// Add unique class for each website sub-section. Zen provides a section.
$path_parts = explode('/', drupal_get_path_alias($_GET['q']), 3);
$path_parts_count = count($path_parts);
if ($path_parts_count > 1) { // We have a sub-section.
if ($path_parts_count > 2) {
array_pop($path_parts);
}
$subsection = implode('-', $path_parts);
$vars['body_classes_array'][] = zen_id_safe('subsection-' . $subsection);
}
$vars['body_classes'] = implode(' ', $vars['body_classes_array']); // Concatenate with spaces
?>
Comments
thanks!
this helped. I was having trouble pulling workable parts from the path.
Post new comment