By Andy on Monday, 17 November 2014
Likes 0
Views 849
Votes 0
I'm adding code to a module and / or article and I want to show the avatars of a couple of known User ID's, and have them link through to the relevant profile pages.

Is there a simple bit of code that I can use if I know for example user ID 123, to show his / her avatar linking to their profile?

Thanks!
Thanks for sharing Alex.

Added information. If you have a user id, then it would be FD::user($userid);

Calling FD::user() without $userid will give you the current logged in user.
·
Tuesday, 18 November 2014 11:00
·
0 Likes
·
0 Votes
·
0 Comments
·
Retrieving User Avatar

To retrieve an avatar of a user, its

$my = Foundry::user();
?>
<img src="$my->getAvatar();" />
Arguments:

$avatarSize - (Optional) If specified, it uses the size provided.

Avatar Sizes

These are available sizes and it's dimension

SOCIAL_AVATAR_SMALL - Smallest version of avatar. Dimensions: 32 x 32
SOCIAL_AVATAR_MEDIUM - Medium version of avatar. Dimensions: 64 x 64
SOCIAL_AVATAR_SQUARE - Large square version of avatar. Dimensions: 180 x 180
SOCIAL_AVATAR_LARGE - Large version of avatar. Dimensions: 180x (y) (This is a proportionate size)
·
Monday, 17 November 2014 21:14
·
0 Likes
·
0 Votes
·
0 Comments
·
Awesome. Thanks Guys.
·
Tuesday, 18 November 2014 11:11
·
0 Likes
·
0 Votes
·
0 Comments
·
Welcome.
·
Tuesday, 18 November 2014 11:38
·
0 Likes
·
0 Votes
·
0 Comments
·
Sorry I need a bit of extra help on this one.

So if my user is User ID 59, what code would I need to drop into a module to show the avatar, linked to the profile page?

If it doesn't make it hugely more complex, what code would show the typical popup that you see elsewhere around EasySocial such that when you hover over the avatar, there's a popup with the user's cover and extra info too.

Thanks!
·
Thursday, 20 November 2014 20:14
·
0 Likes
·
0 Votes
·
0 Comments
·
Just to add... it's a non-EasySocial page I'm trying to make this work on.
·
Thursday, 20 November 2014 21:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Andy,

Did you mean you want to load User ID 59, and want to retrieve his profile link? If so, you can use this code:

$user = FD::user('59'); //load the user
$profileLink = $user->getPermalink());


Hope this helps.
·
Friday, 21 November 2014 00:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Yes I think that's the start of it.... but I want to display their avatar. The 2 lines above don't actually output anything to the screen right?

So I've opened a new Custom Code Module (one that'll take PHP code) and I want to paste in the magic code that'll show me User 59's avatar, linked to their profile page. I just struggling to get that code right.

It it's not tricky I'd love that pop-up you guys do when you get to see the person's cover pic and other options on avatar mouse over too, but the main objective is to get workable code to show the avatar pic and have it hyperlink to the profile page.

Thanks if you can just nudge me along to the finish line on this one!
·
Friday, 21 November 2014 00:50
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Andy,

For the avatar, you can follow the previous reply by Alexandre:

<img src="/$my->getAvatar();" />


Arguments:
$avatarSize - (Optional) If specified, it uses the size provided.

Avatar Sizes
These are available sizes and it's dimension
SOCIAL_AVATAR_SMALL - Smallest version of avatar. Dimensions: 32 x 32
SOCIAL_AVATAR_MEDIUM - Medium version of avatar. Dimensions: 64 x 64
SOCIAL_AVATAR_SQUARE - Large square version of avatar. Dimensions: 180 x 180
SOCIAL_AVATAR_LARGE - Large version of avatar. Dimensions: 180x (y) (This is a proportionate size)
·
Friday, 21 November 2014 01:09
·
0 Likes
·
0 Votes
·
0 Comments
·
You got the avatar plus the link. If you want some kind of bubble effect. Go on google and type: bootstrap popover

That shall explain you the basic
·
Friday, 21 November 2014 01:15
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Andy,

I'm sorry that I missed it. You should use this instead:

<?php
$user = FD::user('1106'); //load the user
$profileLink = $user->getPermalink());
echo '<img src="' . $my->getAvatar() . '" />';
?>
·
Friday, 21 November 2014 01:20
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Nik. Thanks for your patience. Your latest code still crashes my page... If I turn on error reporting I see:

Parse error: syntax error, unexpected ')' in /mysite/tmp/htmlm3lqIb on line 3

Are all the brackets in place right in your example (sorry I'm no good on coding) and maybe should the $my be $user... or is that all looking good on a double check?

Got to run now. Back in an hour.
·
Friday, 21 November 2014 01:28
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Andy,

I'm sorry. Can you try this:


<?php
$user = FD::user('1106'); //load the user
$profileLink = $user->getPermalink());
?>
<img src="<?php echo $user->getAvatar();?>" />


I've tried in my local and it is working.
·
Friday, 21 November 2014 01:36
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Nik,

Ok I'm getting there!.... If I use your latest code without the $profileLink line, it shows the avatar perfect (just had to remove the extra forward slash at the start of the img source)

.. but if I include the $profileLink line I get a crashed white screen. Is it to do with the Permalink being something not every user sets?! Is there an alternative profile linking method (typically my profile pages show the User ID number in them) and / or any way to link without the page crash?
·
Friday, 21 November 2014 02:58
·
0 Likes
·
0 Votes
·
0 Comments
·
Use router instead
·
Friday, 21 November 2014 03:23
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks Alexandre - Sorry to be clueless but what is 'router' and how would you use it here?
·
Friday, 21 November 2014 03:32
·
0 Likes
·
0 Votes
·
0 Comments
·
FRoute:: profile(array('id' => $id));
·
Friday, 21 November 2014 06:25
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks everyone. All working great for me now!!!!!
·
Friday, 21 November 2014 07:49
·
0 Likes
·
0 Votes
·
0 Comments
·
Enjoy :P
Nik you owe me a beer... maybe half one considering the help on dating search module
·
Friday, 21 November 2014 08:42
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Andy,

You're welcome. Lol Alexandre! Thanks for sharing. If you come to Malaysia, I'll buy you a drink.
·
Friday, 21 November 2014 10:14
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post