PDA

View Full Version : Easy way to put user's avatar on any page


Derpstra
08-20-2012, 04:05 PM
Being a very lazy person, I like to make my scripts as simple as possible. Usually I achieve this by messing around with the functions. Today I made an easy one that allows you to put the user's avatar wherever you want!

First, add this function to the page functions/functions_users.php:

function usernametoavatar($name){
$row = $GLOBALS['adopts']->select("users_profile", array("username", "avatar"), "username='{$name}'")->fetchObject();
return $row->avatar;
}


Now, on whatever page you want to add their avatar to, paste this anywhere on the page before $article_title:

$avatar = usernametoavatar($username);


Then, in your $article_content, place this wherever you want the avatar to show up:

<img src='{$avatar}' />


Ta da! They will see their own avatar! :smile: