2

Using Views and Panels, I have an unordered list of node teasers that appears on every page. When viewing a node, I would like to highlight that node's teaser in the list.

Class .active gets applied to the teaser link, but I'd like to apply it to the whole list item. Is this possible?

1 Answer 1

2

The following does the work for me:

function YOUR_THEME_preprocess_views_view_unformatted(&$vars) {

  if (arg(0) != 'node') return; // no active node

  $index = 0;
  foreach($vars['view']->result as $node) {
    if (arg(1) == $node->nid) {
      $vars['classes_array'][$index] .= ' active';
    }
    $index++;
  }

}
2
  • is that method only works for unformatted style? because I am getting error Notice: Undefined offset: 2 for table style (where 2 is the $index value) but working fine with unformatted style.
    – kiranking
    Dec 3, 2015 at 19:13
  • ok got it. for YOUR_THEME_preprocess_views_view_table $vars['row_classes'][$index][] should be used instead of $vars['classes_array'][$index]
    – kiranking
    Dec 4, 2015 at 4:47

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.