Add class based on published state I am trying to add a body class to my site in template.php based on whether or not a node is published or not. I had a look around here and on drupal.org and pieced together some code but I am getting an error. Here is what I have tried so far:

function responsive_process_html(&amp;$variables) { 

 if ($node-&gt;status == 1){
        //$variables['#attributes']['class'][] = 'pub';
        $variables['classes_array'][] = 'published';
    }

    else {
        $variables['classes_array'][] = 'not-published';
    }
}


... but I am getting this error:

Notice: Undefined variable: node in responsive_process_html() (line 37 of /sites/all/themes/responsive/template.php).
Notice: Trying to get property of non-object in responsive_process_html() (line 37 of /sites/all/themes/responsive/template.php).


I also tried $variables['#attributes']['class'][] = 'published'; instead of $variables['classes_array'][] = 'published'; but it made no difference.
in your theme's template.php:

function mytemplate_preprocess_html(&amp;$vars) {
  $node = menu_get_object();
  if ($node &amp;&amp; isset($node-&gt;nid)) {
    if ($node-&gt;status) {
      $vars['classes_array'][] = 'published';
    } else {
      $vars['classes_array'][] = 'unpublished';
    }
  }
}