Hi,
to get user id or user name (who has created a node) I can use the following code:

$node->uid (for user id)
$node->name (for user name)

But how can I get user group name (or user group id), which is actually log in ? I want to use this code in Content Templates. Thank you for any suggestions.

Comments

cog.rusty’s picture

What kind of user group?

norti’s picture

I'm sorry. I want to display a ROLE name. I thought that the "global $user; print $user->roles" code could show me the role name, but I get only "Array" text. "$user->roles[0]" or "$user->roles[1]" don't work too.

nancydru’s picture

Are you using OG? If not, are you talking about "role?"

If you mean role, you can use user_load to get the user's information. Part of that is an array containing their roles.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

norti’s picture

I'm sorry. I want to display a ROLE name. I thought that the "global $user; print $user->roles" code could show me the role name, but I get only "Array" text. "$user->roles[0]" or "$user->roles[1]" don't work too.

nancydru’s picture

You're saying "group," does that mean you're using OG? If not, do you mean "role?" You can get the user's role with user_load. The loaded object includes an array of the user's roles.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

nancydru’s picture

You're saying "group," does that mean you're using OG? If not, do you mean "role?" You can get the user's role with user_load. The loaded object includes an array of the user's roles.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

nancydru’s picture

You're saying "group," does that mean you're using OG? If not, do you mean "role?" You can get the user's role with user_load. The loaded object includes an array of the user's roles.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

fasteasuain’s picture

how about using arg(1) or arg(2)?
this argument denotes the group id while you're in a group page