load node author uid to be used as contextual link inside template.php D7 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(&amp;$build) { 

         $node_author = user_load($node-&gt;uid);

          // Add your own custom link
          $build['links']['node']['#links']['user-post'] = array(
            'title' =&gt; t('User post'), 
            'href' =&gt; '/userview/' . $node_author . '/post', 
            'html' =&gt; TRUE, 
            'attributes' =&gt; array(
              'title' =&gt; 'User post',
            ),
          );


        }
You have just a tiny mistake , use $build['#node']->uid instead $node->uid  :)

function MYTHEME_node_view_alter(&amp;$build) { 

         $node_author = user_load($build['#node']-&gt;uid);

          // Add your own custom link
          $build['links']['node']['#links']['user-post'] = array(
            'title' =&gt; t('User post'), 
            'href' =&gt; '/userview/' . $node_author . '/post', 
            'html' =&gt; TRUE, 
            'attributes' =&gt; array(
              'title' =&gt; 'User post',
            ),
          );


        }