Add classes to body tag
Sometimes you want to add classes to the body tag to able to theme the site as you want it. Here is one way of doing it by changing a function call in page.tpl.php and add some code to the function phptemplate_body_class() in template.php.
<?php
//In page.tpl.php add two arguments
<body <?php print phptemplate_body_class($left, $right, $node->type, arg()); \?\>>
//In template.php add the two arguments
//Add the code below or change it to add the classes
function phptemplate_body_class($left, $right, $type="", $args="") {
if ($args[0] == "node") {
if ($args[1] == "add") {
$extra .= "node-add-".$args[2];
}elseif($args[2] == "edit"){
$extra .= $type."-node-edit";
}else{
$extra .= $type."-node-view";
}
}
if ($left != '' && $right != '') {
$class = 'sidebars';
}else {
if ($left != '') {
$class = 'sidebar-left';
}
if ($right != '') {
$class = 'sidebar-right';
}
}
if (isset($class)) {
print ' class="'. $class .' '.$extra.'"';
}elseif(!empty($extra)){
print ' class="'.$extra.'"';
}
}
?>
Knowledge keywords: