Popular
- Drupal 6 - Generate additional path alias when updating or adding a taxonomy term
- Drupal 6 - Return menu markup for a top level term with its children
Tags
- Drupal
- Drupal 7
- jQuery
- Ubercart
Oldies
- October 2011
- August 2011
- July 2011
- June 2011
Tag: Drupal 7
Drupal 7 – Add page and section body classes
October 6, 2011
Add this snippet to the template.php file in the THEMENAME_preprocess_html()
hook.
<?php
global $base_path;
list(,$path) = explode($base_path, $_SERVER['REQUEST_URI'], 2);
list($path,) = explode('?', $path, 2);
$path = rtrim($path, '/');
// Construct the id name from the path, replacing slashes with dashes.
$body_id = str_replace('/', '-', $path);
// Construct the class name from the first part of the path only.
list($body_class,) = explode('/', $path, 2);
// $body_class = $body_class . ' not-front';
$body_id = 'page-'. $body_id;
$body_class = 'section-'. $body_class;
$vars['classes_array'][] = ' ' . $body_id . ' ' . $body_class;
?>
Leave a comment
Tags: Drupal 7