Hi, I'm looking to print the default picture if a user isn't logged in. It's in an if else statement, and right now the If statement works for users who are logged in, I have it displaying their picture, just not sure how to display the sitewide default image if they aren't logged in.

Thanks

Comments

aterink’s picture

This works for me

 if($user->picture) {print theme('user_picture', $user);}
else {
print '<img src="directory/to/files/blankuser.png" alt="" />';
}

Reading what you're asking for again you may have to change it. Do you want it to display the picture of the user viewing the page?

anthonylicari’s picture

It will be displaying the user viewing the page. I already have <?php global $user; ?> the thing is, is that the else statement I have it set up already like you have but there is some caching and flickering going on where if you just click on a page the image loads fine, but if you hit refresh it will only display the alt tag. If you travel back to the page the image shows up again. Hit refresh, it goes away. This only is happening for the anon user so I was hoping to find a better solution for the else statement.

umarbukhari’s picture

if($user->picture) {print theme('user_picture', $user);}
else {
print '<img src="/directory/to/files/blankuser.png" alt="" />';
}

Try this one.

beautifulmind’s picture

...I'm looking to print the default picture if a user isn't logged in...

Well, what do you wanna do?
You can configure default user picture from admin > user settings.
According to your above statement, if you don't wanna show any registered user's picture to anonymous users, you have do following.

 if ($user->uid > 0) {
   //show picture
 }
 else {
    //show default picture.
 }

Regards.
🪷 Beautifulmind