Ok, I am not a big coder so this may be obvious for some.

I am having problems trying to get user's badges displayed elsewhere on the site (ie. Forum topics & comments)

I have found out that the following code displays badges but only for a specified user:
print user_badges_for_user(array('uid'=>$accountid));

How do I make this dynamic and place it in my PHPTemplate theme files to display where I want it (ie. Forum topics & comments)?

Any help is much appreciated!

-- Marand B.

Comments

Marandb’s picture

Hmmm... No one?

-- Marand B.

heine’s picture

Category: feature » support
Status: Active » Fixed

For example

  print user_badges_for_user(array('uid' => $node->uid)); // in node.tpl.php uid of node owner
  print user_badges_for_user(array('uid' => $comment->uid)); // in comment.tpl.php uid of node owner
heine’s picture

That last comment should have been // in comment.tpl.php uid of comment owner.

BTW: The new version of user_badges will have a user_badges_for_uid() that is much lighter on the database because:
1. It doesn't load the user object
2. It caches retrieved badges

Marandb’s picture

Thank you. I will check out the newer version as well.

This should really help out my site.

-- Marand B.

theunraveler’s picture

Version: master » 4.6.x-1.x-dev

How do I get the user badges to appear next to the names of the users that are online in the "Who's Online" module? I tried to do it using modified versions of the code pasted above, but to no avail. Can anyone help me out?

heine’s picture

I've no idea what the 'who's online' module is. 4.6 just had the bugfixes from 4.7 applied and only just now has the user_badges_for_uid function (see http://drupal.org/node/28083#comment-118908. Remember that this was an issue against CVS, not 4.6!).

Please open new issues, instead of attaching to this one.

Anonymous’s picture

Status: Fixed » Closed (fixed)