/ Published in: PHP

Automatically add a class to the body tag on each page. Remember to add
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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 $body_classes[] = phptemplate_format_class('page-' . $path); // set body_classes var with spaces in between each class if (module_exists('path')) { if ( $alias != $_GET['q'] && $alias == $_REQUEST['q'] ) { $template_filename = 'page'; $template_filename = $template_filename . '-' . $path_part; $suggestions[] = $template_filename; } } $vars['template_files'] = $suggestions; } } //Helper Function for formatting css class names function phptemplate_format_class($string) { }
Comments
