User Profile avatar/picture Snippet
PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
Description
This php snippet checks to see if the user has a picture/avatar uploaded and displays it if they have.
Dependencies: No extra modules required but picture support must be enabled to allow users to upload their avatars/pictures:
1) admin/themes/settings/*yourtheme*
Enable 'User pictures in posts' and 'User pictures in comments'
2) admin/settings/user
'Enable' Picture support. You can also set size of avatar.
Usage
- For use in your user profile page override
- Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
- Tested and works with Drupal 4.5 and 4.6
- Change the div class names or the prefix text to suit.
<?php if ($account->picture) { print theme('user_picture', $account); } ?>NOTES: Thanks to leafish_paul for improving this snippet.

Working in Drupal 5 + no picture support
<?php if($user->picture) {print theme('user_picture', $user);}else {
print '<img src="/path/to/nopicture.gif" alt="This user hasn't posted a picture yet or whatelse" />';
}
?>
This version works in Drupal 5 but I added an else to display a no-picture picture so the space is not left empty on profiles without a user picture.
code for This user not posted picture is not working
hi..
i am gettting a parse error..is there something wrong with the code for 5.1
pls help.
thanks
try this
I think there's an extra apostrophe in there..
<?php if($user->picture) {print theme('user_picture', $user);}else {
print '<img src="/path/to/nopicture.gif" alt="This user hasn\'t posted a picture yet or whatelse" />';
}
?>
Note how you put a backslash before the apostrophe in
hasn'thope that helps
Dub
Also, I think that it can be
Also, I think that it can be written like this too:
<?phpif ($user->picture) {
print theme('user_picture', $user);
}
else {
print '<img src="/'.variable_get('user_picture_default', 'path/to/default.gif').'" alt="Default User Picture" />';
}
?>
or for use in various node template files:
<?phpif ($node->picture) {
print theme('image', $node->picture);
}
else {
print '<img src="/'.variable_get('user_picture_default', 'path/to/default.gif').'" alt="Default User Picture" />';
}
?>
the
variable_getmeans that you can still us the administrative interface to update the default user picture down the road, rather than have to go back and edit all the files where you have this code.A mix works for me
<?phpglobal $user;
if ($user->uid) {print theme("user_picture",$profileuser);}
else {
print '<img src="/'.variable_get('user_picture_default', '/noavatar.png').'" alt="Default User Picture" />';
}
?>
Put this code to your "node-profil" template.
www.yoci.de
Best Practice
It's generally a good idea to run any user-displayed text - even image alt tags - through Drupal's t() function, in case your theme gets used on a site which uses the various foreign language modules. No biggie, just something like this:
<?php... .'" alt="'. t('Default user picture') .'" />'...
?>
--Andy
Developing Drupal websites for Livelink New Media
Block pictures in pages and not in blogs ?
Is it possible to show avatars only in blogs and comments but not in pages/stories ?
How to do it please ?
Tiziano
What about
What about
<?php print $picture ?>?__
SEO Tips For Successful Drupal Sites
__
Cape Verde News & Community
My Info Collection
D6?
What would be the equivalent in Drupal 6?
it works!
<?phpif($user->picture) {
print theme('user_picture', $user);
}
else { print '<img src="/images/avatar.gif"/>';}
?>