Posted by NeoID on March 12, 2009 at 9:12am
Jump to:
| Project: | User Badges |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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?
Comments
#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.
#5
Is there a newer, more automated solution to username colours?
#6
To answer my own question: combination of viewers and colorpicker can achieve a similar result based on roles:
http://drupal.org/project/viewers
#7
The viewers/colorpicker hack only works for the viewers module, but your php snippet, Likeless, works excellent. Thank you!