How do I print out the author's role in node.tpl?

Comments

mndonx’s picture

Hi hellomobe-

First you need to load the information you want since it isn't available automatically in the node:

<?php $account = user_load(array('uid' => $node->uid)); ?>

So now the $account variable holds all the information about your node's author.

The tricky part is that sometimes the author can have more than one role, so you may want to print them all out with commas separating them.

<?php 
  $author_roles = array();
   foreach ($account->roles as $key=>$value) { //cycle through each role the author has
     $author_roles[] = $value;
   }
   echo implode(', ', $author_roles); //comma separation
?>

Hope that works for you.
-Amanda

hellomobe’s picture

Thank you Amanda!

I also found this to eliminate the "authenticated user". I modified ithe code from the link below with your user_load()

 $account = user_load(array('uid' => $node->uid));
          foreach ($account->roles as $role)
  {
  if ($role != 'authenticated user') // mask that role
    {
    print ("  <li>$role</li>\r\n") ;
    }
  }
	

source: http://blog.riff.org/2005_08_24_drupal_admin_displaying_user_roles_on_th...