I need to load node author uid to be used as part of a href link inside template.php, I managed to add a contextual link according to this post, and call it from node.tpl.php but I can't access node author uid to complete my link. I have a view with the following path: /userview/%/post
, link inside node.tpl.php it appears, but does not work. I tried to do it by custom module, but I do not know how to load the 'node being viewed' in a custom module, that's why I'm trying to do it in template.php. Any help will be appreciated.
This is my code in template.php
function MYTHEME_node_view_alter(&$build) {
$node_author = user_load($node->uid);
// Add your own custom link
$build['links']['node']['#links']['user-post'] = array(
'title' => t('User post'),
'href' => '/userview/' . $node_author . '/post',
'html' => TRUE,
'attributes' => array(
'title' => 'User post',
),
);
}
node.tpl.php
. Please refer here. Hope this will help you.