Fix for adding a view name class to page.tpl.php

  1. // in template.php
  2. function _phptemplate_variables($hook, $vars) {
  3.         switch ($hook) {
  4.        
  5.         case 'page':
  6.                 foreach (views_get_all_urls() as $key => $value) {
  7.                         if($_GET['q'] == $value) {
  8.                                 $vars['views_class'] = yourtheme_id_safe($value);
  9.                                 }
  10.                         }
  11.                 break;
  12.                 }
  13.         return $vars;
  14. }
  15.  
  16. // borrowed this from zen :)
  17. function yourtheme_id_safe($string) {
  18.   if (is_numeric($string{0})) {
  19.     // if the first character is numeric, add 'n' in front
  20.     $string = 'n'. $string;
  21.   }
  22.   return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
  23. }
  24.  
  25.  
  26. // in page.tpl.php add this to your body class (or anywhere)
  27. <div class="page<?php print ($views_class) ? ' page'- . $views_class : ''; ?>">