-1

I am showing nodes from a 'news' content type in a view. In this view I want to add a CSS class to the unpublished items. So, am I able to style (e.g. red background color) on the unpublished items?

How can I do this? Is there a way to write a hook in template.php?

  • Don't nodes by default already have a class like node-unpublished? – Neograph734 Sep 20 '17 at 9:21
0

See if this works for you. In your theme's template.php:

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

You need to define classes_array with whatever classes you need to be added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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