0

I have a D7 site with search_api module, I'd like to change border color of nodes in views results if logged in user equals node author, in plain English, make easy to logged in users identify its own content in views results.

2 Answers 2

0

You'll need to check this in a preprocess hook. You can load the global $user object and have views report the node author. In the preprocess hook you can check $user->uid against $node->uid and set a variable so you know in your tpl.php file which css class to set in your wrapper.

1
  • thanks @lynbermt, could you please add more details on your answer?
    – pinueve
    Oct 7, 2015 at 0:27
0

You can check the author condition in theme_preprocess_search_api_page_result function. You can add a class to the result where the current user is the node author.

function theme_preprocess_search_api_page_result(&$variables) {
  global $user;
  if ($variables['item']->author == $user->uid) {
    $variables['classes_array'][] = 'node-author';
  }
}

I'm not sure of the 'if condition', you can print the $variables to confirm it.

.node-author {
  border: 1px solid black;
}

To add border, you can add the above css to your style.css or the css file you wish to add.

Hope this helps!

3
  • Hi @Suresh, thanks for a good and detail answer, but I'm having problems, I think is the function name, I google it and I can not find anything about it. I have other functions in my template.php working fine, but not this one. I have tryed template_preproccess_[node, page, html, views_view, search_result, search_results, etc], but no luck. Any other function that you could please recommend? ofcourse I'm changeing 'template' with my themename.
    – pinueve
    Oct 7, 2015 at 23:57
  • Hi @pinueve, did you use 'theme_preprocess_search_api_page_result'? also don't forget to clear the cache for the changes to take effect
    – Suresh R
    Oct 8, 2015 at 4:45
  • Yes, with your hook nothing happens, no dpm() print, other hooks do print dpm(), but incorrect hook. in view--tpl.php I have dpm($rows), I see all data, node by node, code looks fine, but no css changes, I looked in api.search_api for hooks, none seems to fit...any ideas..?,... thanks.
    – pinueve
    Oct 8, 2015 at 5:31

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.