<?php
/**
* This snippet creates a <body> class and id for each page.
*
* - Class names are general, applying to a whole section of documents (e.g. admin or ).
* - Id names are unique, applying to a single page.
*/
// Remove any leading and trailing slashes.
$uri_path = trim($_SERVER['REQUEST_URI'], '/');
// Split up the remaining URI into an array, using '/' as delimiter.
$uri_parts = explode('/', $uri_path);
// If the first part is empty, label both id and class 'main'.
if ($uri_parts[0] == '') {
$body_id = 'main';
$body_class = 'main';
}
else {
// Construct the id name from the full URI, replacing slashes with dashes.
$body_id = str_replace('/','-', $uri_path);
// Construct the class name from the first part of the URI only.
$body_class = $uri_parts[0];
}
/**
* Add prefixes to create a kind of protective namepace to prevent possible
* conflict with other css selectors.
*
* - Prefix body ids with "page-"(since we use them to target a specific page).
* - Prefix body classes with "section-"(since we use them to target a whole sections).
*/
$body_id = 'page-'.$body_id;
$body_class = 'section-'.$body_class;
print "<body class="$body_class" id="$body_id"";
print theme('onload_attribute');
print ">";
?>
Drupal 6个独特的身体类
Automatically add a class to the body tag on each page. Remember to add
/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars){
// Add unique classes for each page and website section
$path= drupal_get_path_alias($_GET['q']);
// append the body classes array with the current path