How to display user avatar in Drupal 7?

13,767

Solution 1

You can use something like:

$user_item = user_load_by_name($username); // or user_load( $user->uid )
print theme('user_picture', array('account' =>$user_item));

Solution 2

When I use the user picture is linked to the user profile. I have set my user images to be displayed as thumbnails. I'd like to link the user picture to the full sized picture and display them using lightboxII. It seems to be a very easy task but I couldn't figure out yet how to do it.

Share:
13,767
Alexey
Author by

Alexey

The bearing of a child takes nine months, no matter how many women are assigned. (Fred Brooks)

Updated on June 04, 2022

Comments

  • Alexey
    Alexey almost 2 years

    I'd like to know how to display a user avatar in Drupal 7. I want to display the avatar in full size and as the thumbnail.

  • Alexey
    Alexey over 12 years
    Thank you for the response. Could you provide some lines of code for better understanding, I'm a new to Drupal.
  • drmonkeyninja
    drmonkeyninja over 12 years
    OK, for example, in your node template (node.tpl.php) you can include <?php print $user_picture ?> where you want the profile picture to appear. If your doing this within a comment template (comment.tpl.php) then use <?php print $picture ?> instead (not sure why, but they're different).
  • Alexey
    Alexey over 12 years
    I get the error: Notice: Undefined variable: user_picture in include() (line 230 of C:\xampplite\htdocs\drupal\sites\all\themes\MyBartik\templat‌​es\page--teams.tpl.p‌​hp). when use this code <?php print $user_picture ?> in page--teams.tpl.php
  • drmonkeyninja
    drmonkeyninja over 12 years
    It won't work in a page template as the page doesn't have a user associated with it like a node or comment. Check out drupal.org/node/190815 which lists all the available core templates and the variables you can use in them.
  • user18099
    user18099 about 8 years
    That is not an answer.
  • user18099
    user18099 about 8 years
    for imagecache sizes (thumbnail etc.): global $user; $imgUrl = $user->picture->uri; theme('image_style', array('style_name' => 'STYLE', 'path' => $imgUrl));