Change color of username based on badge
NeoID - March 12, 2009 - 09:12
| Project: | User Badges |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Hi,
Would it be possible to extend this module (or code snippet), that changes the colour of the username if he/she has a certain badge?

#1
Well you can do that within your theme when printing usernames. Just give it a class and then simply define which colour for which role / badge into your css file.
Cheers!
#2
Thought I had found a solution some time ago, but I'm not happy with it..
Anyway, I've this function, anyone knows why the $badges->name isn't printed at all?
<?phpfunction phptemplate_username($object) {
return '<span class="'. strtolower($badges['name']) .'">'.theme_username($object).'</span>';
}
?>
#3
Try this. I've not tested it, but it should add classes based on the badge id number.
<?phpfunction phptemplate_username($object) {
if ($object->uid && $object->name) {
$output = '<span class="';
$badges = user_badges_get_badges($object->uid);
foreach ($badges as $bid => $badge) {
$output .= " userbadge_$bid";
}
$output .= '">' .theme_username($object). '</span>';
return $output;
}
else {
return theme_username($object);
}
}
?>
#4
Automatically closed -- issue fixed for 2 weeks with no activity.