Is it possible for the user's role to be displayed underneath their user pictures in both the comments, nodes and on their profile pages?
Is it possible to make this happen for only certain roles (so a moderator or administrator would have the role text, but a normal user would not)?

Comments

amirtaiar’s picture

so if you have it please let me know
i would like the profile picture to be add auto to the node publish by this profile.
thank you

Managing Partner at Reasonat

man.of.munch’s picture

Sorry, I still don't know. Is there anyone who know the answer???

casualfatboy’s picture

u can use User Badges module. usually it is used to display pictures according to the user role.u can type needed text in photoshop and display it with needed roles)

also there is User Titles module,but i havent seen it, maybe u should review it too.

amirtaiar’s picture

unfortunately both are for Drupal 5 yet no 6.
is there another module you know about?
thank you

Managing Partner at Reasonat

man.of.munch’s picture

That is a shame, I am using drupal 6 too.

gforce301’s picture

If you create a custom user-picture.tpl.php for your theme you can display whatever information you wish, based on whatever criteria you want.
Read this --> http://api.drupal.org/api/file/modules/user/user-picture.tpl.php

You should familiarize yourself with the api as it will help you.

man.of.munch’s picture

I read the link you posted and it seems pretty straightforward however I don't know php and have no idea how to print the user's role.
Do you have any code for this, or is there anywhere that I can find some?

HS’s picture

I've been looking for an option to display the User's Role as well. Nothing seems to be available for Drupal6 which is a wee bit frustrating. I came across this. I am yet to try it. Let me know how it goes.

barrett’s picture

To get the role(s) you should be able to go through the global $user object to the roles array. Keep in mind though that a user may well have more than one role (apparently, I can't claim to be a ninja). So you need to either grab just one or concatentate them all into a single string.

Search from roles on this page (http://www.bywombats.com/blog/ryan/10-25-2007/checking-if-drupal-user-ha...) and you should get an idea of what needs to happen.

HS’s picture

Barrett,

Thanks for responding but I'm a total newb and don't understand what I should edit. I however found this will it work on D6?

barrett’s picture

Okay. Start from the source code of the user-picture.tpl.php (http://api.drupal.org/api/file/modules/user/user-picture.tpl.php/6/source) which gforce301 linked you to earlier in the thread. That gives you a shell file that you can start modifying to work how you want.

Then add in the role handing you just linked to. You already have a user object though, so you don't need to load one explicitly. The code you referenced is also only going to print the last role in the user's list of roles, so it's probably desirable to modify that code to concatenate them all into one string which you can print. The code below is what I'd use.

  $roleList='';  //empty variable to hold the output  
  foreach ($user->roles as $role) {
      $roleList .= t(" (%role)", array('%role' => $role,)); //concatenate each role onto the roleList
  }
  print "<div id=\'picture_role_list\">$roleList</div>";  //output

Then add the snippet to the tpl.php file under where it prints the picture variable, save the whole thing to user-picture.tpl.php and save that file in your theme directory.

Keep in mind, I haven't tested the code, but it should work.

tryitonce’s picture

Thanks,

at least this solution works - lots of others I tried along the way didn't.

Now I am wondering, if there is a simple way to eliminate "authenticated user" from the list or to rename it to something shorter and to the point, i.e. "member".

Thanks

barrett’s picture

  $roleList='';  //empty variable to hold the output 
  foreach ($user->roles as $role) {
      if($role == "authenticated user") {
          $newrole = "member";
      }
      else {
          $newrole = $role;
      }
      $roleList .= t(" (%role)", array('%role' => $newrole,)); //concatenate each role onto the roleList
  }
  print "<div id=\'picture_role_list\">$roleList</div>";  //output
tryitonce’s picture

great - it works well and thanks for the quick help!!!!

I then found that the ($user->roles as $role) -of course returns- the roles of the person who is logged on.

I wanted to add the snippet to my user-profile.tpl.php file in order to jazz up the customised user profile on my site.

The answer seems to be to change the snippet for my purpose as follows by replacing $user for $account:

<?php
  $roleList='';  //empty variable to hold the output
  foreach ($account->roles as $role) {
      if($role == "authenticated user") {
          $newrole = "member";
      }
      else {
          $newrole = $role;
      }
      $roleList .= t(" (%role)", array('%role' => $newrole,)); //concatenate each role onto the roleList
  }
  print "<div id=\'picture_role_list\">$roleList</div>";  //output
?>

I then also wanted to add the Joining date / time joined and found the following snippets and changed them accordingly to show the details of the account not the user.

<div class="fields">Joined:<?php //pre-text 
$date_type = 'custom';
$custom_type = 'd/m/Y'; //Date format customization 
print (format_date($account->created,$date_type,$custom_type));?>
<BR>
<span class="member-for">(<?php print (format_interval(time() - $account->created));?>)</span>
</div>

Of course for a lot of our much longer serving colleagues here all this is properly very obvious and even I must chuckle a bit looking back - how could it not have been clear - I am the $user and the others are the $accounts.

Great fun to learn all this and thanks to the credit crunch I have the time to do something interesting - and thanks to all those helping friends around here.

barrett’s picture

D'oh! Yeah, I completely misread what you were going for there. Glad you worked it out.