avatar on the blog

Permalink 3 users found helpful
Hi,
Is it possible to display users avatar on posts on the blog?

e.g
I have three users, and everyone writes your posts.
On page list I can show who posted any post
<?php   echo $author; ?>
, but how I can show his avatar?

cssninja
View Replies: View Best Answer
buildingsomethingonline replied on at Permalink Best Answer Reply
buildingsomethingonline
You need this code...yep had this problem before :)
$username = $c->getVersionObject()->getVersionAuthorUserName();
         $ui = UserInfo::getByUserName($username);
         if ($ui->hasAvatar() == true) {
            $av = '<img src="'.BASE_URL.DIR_REL.'/files/avatars/'.$ui->getUserID().'.jpg'.'" alt="avatar" />';
            echo $av;
         } else {
            echo 'No avatar detected. LOLOLOLOLOL';
         }
cssninja replied on at Permalink Reply
cssninja
Thanks, it works! :)
agentorange replied on at Permalink Reply
agentorange
I would vote this best answer again if I could- worked great!
onemhz replied on at Permalink Reply
onemhz
@windhack your code work fine, but it only read userinfo nr 1 !!!

this removes this problem:
http://www.concrete5.org/community/forums/customizing_c5/how-to-rem...
$u = new User();
$userName = $u->getUserName();
$ui = UserInfo::getByUserName($userName);
 if ($ui->hasAvatar() == true) {
 echo '<img src="'.BASE_URL.DIR_REL.'/files/avatars/'.$ui->getUserID().'.jpg'.'" alt="'.$userName.'" />';
 }
junebird replied on at Permalink Reply
junebird
Hi There, I applied this to the page list on my home page, and it works perfectly fine when I'm logged in, but when I log out and look at the page it show this fatal error... what am I doing wrong?
Fatal error: Call to a member function hasAvatar() on a non-object in /home/smi65/public_html/websitenam.com/conc/concrete/blocks/page_list/view.php on line 26.
On line 26 it's: if ($ui->hasAvatar() == true) {
drm92 replied on at Permalink Reply
I have this exact same problem, did you fix this?
somesayinice replied on at Permalink Reply
Sorry to resurrect and old thread but I think this is a better answer. A little cleaner. Uses helpers.

<?php
$username = $c->getVersionObject()->getVersionAuthorUserName();
$ui = UserInfo::getByUserName($username);
$full_name = $ui->getAttribute('full_name');
if ($ui->hasAvatar()) {
          $avPath = Loader::helper('concrete/avatar')->getImagePath($ui); //Path to user avatar
} else {
          $avPath = Config::get('concrete.icons.user_avatar.default'); //default icon path if no avatar
           }
?>
//HTML OUTPUT
<img class="avatar avatar_img" src="<?php echo $avPath; ?>" alt="'.$full_name.'"/>