I'm looking forward to implement taxonomy terms based CSS styling; especially for the body tag which I want to add the current terms.

Here is what I have so far:

function _phptemplate_variables($hook, $vars = array()) {
  global $node;

  switch ($hook) {
    case 'page':
      // die ('test');
      $vars['body_class'] = '';
      if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
        $vars['body_class'] = 'theme' . arg(2);
      if (arg(0) == 'node' && is_numeric(arg(1))) {
        $node = node_load(arg(1));

        if (is_array($node->taxonomy)) {
          foreach ($node->taxonomy as $term) {
            $vars['body_class'] .= 'theme'.$term->tid;

      if (drupal_is_front_page()) {
        $vars['body_class'] .= ' front';

  return $vars; 

I think the code is OK, but it never get called (see my 'die' function); using simple phptemplate engine and minimal Drupal 6 install.

What obviousness am I missing here?

2 Answers 2


The reason it is not called is because hook_preprocess_variables is for Drupal 5: you should use hook template_preprocess_page in Drupal 6.

So if your theme is called "mytheme", the function would be best named "mytheme_preprocess_page" in your template.php.

Also, Drupal and the Taxonomy modules already generate many body classes, so you should check out what classes already exist because it may be that you don't need to preprocess the page at all (if all you want is to add a body class depending on taxonomy).

  • right ! did the job !
    – Disco
    Commented Mar 29, 2011 at 14:18
  • I'm glad it worked :)
    – wildpeaks
    Commented Mar 29, 2011 at 14:20
  • 1
    Additionally, the code that loads the node object is not necessary, as such object is already passed in $vars['node'], when the page is showing a node content.
    – apaderno
    Commented Mar 29, 2011 at 14:39

Well, years ago we wrote this up http://openconcept.ca/blog/jmlane/taxonomy_specific_css

It would need to be updated I expect for Drupal 6 or 7 but the principals still apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.