global $user ;
$role_array = $user->roles;
//it print the all role from the role table
foreach ($role_array as $role)
{
echo $role;// role from the role table which created
if($role='jobseeker')
{
echo "jobseeker user"; //it print this if user is the jobseeker
}
}
means this code u can put in any place of your page/node
but actually what u want to do,means u want to display all role ya check the current user's role
I just made a user-profile.tpl.php file in my theme folder, copied the original user-profile content and pasted your code and it showed the user role, but i wish i can make it only show the last role, it shows "authenticated userStudents" Students being the second role
Got any clue of how to make it only show the last role in place?
global $user ;
$role_array = $user->roles;
//it print the all role from the role table
foreach ($role_array as $role)
{
if($role='userStudents')
{
echo $role; //it print Students role only
}
}
echo $role // it prints the last role of role table
your last role is fixed so u can echo the $role variable after the forech loop
The above bits of code all have one problem. They show the *viewing* user's roles on ALL users' profile pages. To see the roles of the profile you are viewing, whether it is the currently logged in user or not, you just change the role array assignment from $role_array = $user->roles; to $role_array = $account->roles;. I did a slightly more direct coding than the above, but here's what worked for me:
Comments
Yes. It involves editing the
Yes. It involves editing the user template files.
You'll probably want to read this on editing user profiles : http://drupal.org/node/35728
Some (untested but basic) example code to display roles:
Still not sure wut to do
I need to be spoon feed this i am not that great at this stuff, can someone tell me where to place the code and what the code exactly is.
Thanks
This is the array of role
hi
means this code u can put in any place of your page/node
but actually what u want to do,means u want to display all role ya check the current user's role
Tulsa
It Worked. I just made a
It Worked.
I just made a user-profile.tpl.php file in my theme folder, copied the original user-profile content and pasted your code and it showed the user role, but i wish i can make it only show the last role, it shows "authenticated userStudents" Students being the second role
Got any clue of how to make it only show the last role in place?
Thanks, man your code worked.
yes you can check by the role
your last role is fixed so u can echo the $role variable after the forech loop
may be it helps
Tulsa
Slight change
The above bits of code all have one problem. They show the *viewing* user's roles on ALL users' profile pages. To see the roles of the profile you are viewing, whether it is the currently logged in user or not, you just change the role array assignment from $role_array = $user->roles; to $role_array = $account->roles;. I did a slightly more direct coding than the above, but here's what worked for me:
Which looks like this on my profile page.