How do you do this? I'm trying to display the user badges specifically next to the users who are online in the "Who's Online?" block of the user.module. Basically, I just want it to see who is online and then put the badges next to their names according to their user roles. Any ideas?

CommentFileSizeAuthor
screen_0.jpg212.83 KBtheunraveler

Comments

heine’s picture

Status: Active » Fixed

This is more a question of adapting drupal, then an issue about the module. What you need to do is copy the functionality of the Who's online block. Easiest is to simply copy & adapt the code from user.module (line 545, user_block, case 3) into a php block for example.

You need to adapt the code from line 568:

 while ($max_users-- && $uid = db_fetch_object($users)) {
   $items[] = format_name(user_load(array('uid' => $uid->uid)));
 }

into something like:

while ($max_users-- && $uid = db_fetch_object($users)) {
  $account =  user_load(array('uid' => $uid->uid));
  // Now $account->badges holds the badges for this user.  
  foreach ($account->badges as $badge) {
    $badges[] = theme('user_badge', $badge);
  }
  // $badges now holds the image badges
  // add it somehow to the item in question  
  $items[] = format_name($account) . theme('user_badge_group', $badges); 
}
Anonymous’s picture

Status: Fixed » Closed (fixed)
BradM’s picture

Title: Displaying user badges in blocks » Displaying user badges in who's online block
Version: 4.6.x-1.x-dev » 5.x-1.x-dev
Status: Closed (fixed) » Active

Can anyone help with the code for drupal 5.x? This code doesn't work with this version.

I'd like to implement this but I think the code has change a bit... and I'm not much of a coder to begin with, so I've tried but can't figure it out.

heine’s picture

Version: 5.x-1.x-dev » 4.6.x-1.x-dev
Status: Active » Fixed

Please open a new issue.

Anonymous’s picture

Status: Fixed » Closed (fixed)