By yofomofo on
I am looking to display a user's role next to their username. I am not that experienced with PHP or Drupal yet, so my skills are a bit limited. The furthest I have gotten is displaying the role of the current logged in user for all usernames, but I am looking to check each user instead.
Maybe I am messing around in the wrong part of the code, though. Most of my attempts at this have been in the theme_username function in the theme.inc file. For such a simple thing this is really giving me some trouble :)
A hint or two to the right way of doing this would be best, but any answer/help is appreciated. Thanks guys!
Comments
I think what you are trying
I think what you are trying to do depends on where you want to display the user role and username. Is it in a block? A node body? Every single time the username is displayed, no matter the context? Also, which theme are you using?
There are two php functions that I find to be very useful in this kind of situation, var_dump, which will give you information about a variable or group of variables, and get_defined_vars, which will give you all of the variables you can use.
So let's say you are looking at a piece of php code and want to know what variables are available for you to use. Just insert this line
var_dump(get_defined_vars());into your code and it will display all the variables that are available.
Hint - the output of this code will be ugly in an html page. Try viewing the page source for an easy-to-read format. I think there's a function that makes it pretty, but I forget what it is.
Awesome, thanks for the
Awesome, thanks for the reply. I will definitely try this when I get home from work.
Also, to answer the first set of questions, I am looking to display the username and role everywhere the username is displayed. Block, node, profile, everything. I am also using the default theme (garland).
Thanks again!
Got it to work :) Thanks for
Got it to work :) Thanks for the helpful hints, it really helped and I will be using this in the future. Below I have posted the small snippet of code that I used in the theme_username function of theme.inc. It works perfectly, just hoping that it is the best way to do it. Took me a week and a half for this, and of course, it's only 4 lines of code...go figure!
Thanks again.
User Badges module is now
User Badges module is now available for Drupal 6.