Hey folks. I'm trying to change a few things on my site using CSS based on the section being viewed. I am sectioning off my site using taxonomy. I've used the taxonomy theme module in the past, but because I only want to change a couple CSS values, that's very inefficient and difficult to deal with.
After looking for a good solution, I discovered that it's fairly easy to give the body tag a class based upon which taxonomy is being viewed (I grabbed this code snippit from http://drupal.org/node/67587 ). The following code placed in the template.php file accomplishes this basic task:
<?php
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {
$prefix = ' b-tax-';
}
if ($hook == 'node') {
$prefix = ' tax-';
}
if (module_exists('taxonomy') && $vars['node']->nid) {
foreach (taxonomy_node_get_terms($vars['node']->nid) as $term) {
$vars['node_terms'] = $vars['node_terms'] . $prefix . eregi_replace('[^a-z0-9]', '-', $term->name);
}
}
return $vars;
}
?>
All I need to do then is add class="<?php print $node_terms; ?>"
to the body tag and I have a body class based on taxonomy. Awesome, right?
So here's what I need help with. I know 0 PHP and I'd like to extend this code a bit to include checking for the front page as well as having it hook into pages made with views.