在template_preprocess_comment加class

範例說明:

User reference指定使用者回應時設高亮!內容類型「比賽」裡面有User reference欄位「主辦單位」,對應到主辦單位的User Id。

需求:

希望該比賽的回應,若是主辦單位(User Reference)回應的話,則讓他變成白底。

作法:

1.在theme的template.php裡面加上

function longhair_preprocess_comment(&$vars, $hook) {
  if(arg(0) == 'node'){
    $node = node_load(arg(1));
    if($node->type =='match' && $vars['comment']->uid == $node->field_operator_bhuntr[0]['uid']){
      $vars['classes_array'][] = 'operator';
    }
  }
}

2.在CSS寫上

#comments .operator{
  background-color: #FFFAEF;
}

完成!