I am trying to display one thing to the author of the node and something different to everyone else viewing it:


global $user;
if ($user->uid == $node->uid)
{ print t('you are THE AUTHOR'); }
else {
print t('you are NOT the author');
}

but I get the negative 'NOT the author' message in all cases, even when the author of the node is the currently logged in user.

The possible catch is that I am trying to use this as the "empty text" of a view.

This should be easy... is there something wrong with my php? Thanks

Comments

merlinofchaos’s picture

Status: Active » Fixed

No variables are filled in for you (and cannot be) in the PHP filter. So $node is not a valid value, and therefore $node->uid is NULL. You have to find and load the node to do this.

You can use $view = views_get_current_view(); to get the view and look at $view->result or look at $view->arg perhaps.

boogsbobo’s picture

Thanks for the quick response,

Instead of going that route, I decided just to make two versions of the block.

Both are identical, except for the "empty text" sections. The first version is aimed at logged-in node authors, and the second block is for everyone else.

I added the block directly into my node-type.tpl.php as follows:

global $user;
if ($user->uid == $node->uid)
{ $view = views_get_view('views_name');
   $display = $view ->execute_display('block_1');
   print $display['content'];
}
else {
$view = views_get_view('views_name');
   $display = $view ->execute_display('block_2');
   print $display['content'];
}

It is working perfectly.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.