3

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.

Daniel
  • 1,155
  • 1
  • 10
  • 15
Alexey
  • 7,127
  • 9
  • 57
  • 94

3 Answers3

9

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));
Pawel Dubiel
  • 18,665
  • 3
  • 40
  • 58
  • for imagecache sizes (thumbnail etc.): global $user; $imgUrl = $user->picture->uri; theme('image_style', array('style_name' => 'STYLE', 'path' => $imgUrl)); – user18099 Feb 20 '16 at 12:08
1

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.

Math
  • 11
  • 2
0

Make sure you enable User profiles in the account settings (admin/config/people/accounts) and then you can display them in templates using $user_profile:-

http://api.drupal.org/api/drupal/modules--node--node.tpl.php/7

The user-picture.tpl.php template will let you override how it is output.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
  • Thank you for the response. Could you provide some lines of code for better understanding, I'm a new to Drupal. – Alexey Aug 02 '11 at 10:57
  • OK, for example, in your node template (node.tpl.php) you can include where you want the profile picture to appear. If your doing this within a comment template (comment.tpl.php) then use instead (not sure why, but they're different). – drmonkeyninja Aug 02 '11 at 12:02
  • I get the error: `Notice: Undefined variable: user_picture in include() (line 230 of C:\xampplite\htdocs\drupal\sites\all\themes\MyBartik\templates\page--teams.tpl.php).` when use this code `` in page--teams.tpl.php – Alexey Aug 02 '11 at 16:59
  • 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 http://drupal.org/node/190815 which lists all the available core templates and the variables you can use in them. – drmonkeyninja Aug 03 '11 at 11:32