MyBB Community Forums
[How To?] How do I get user avatar on the index? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: [How To?] How do I get user avatar on the index? (/thread-167139.html)



How do I get user avatar on the index? - expat - 2015-02-16

Quote:<img src="{$mybb->user['avatar']}" alt="{$mybb->user['username']}" class="avatar" />

why wont this work?


RE: How do I get user avatar on the index? - Nasyr - 2015-02-16

Do you mean you want avatars to appear on the forums? Like for the last poster in that forum?


RE: How do I get user avatar on the index? - Firelad - 2015-02-16

EDIT: Nevermind, you're right. I don't know why.
EDIT 2: Looks like at the end it has '/>'. I don't think it works in HTML5 anymore, and what I had used in mine was <img src="{$mybb->user['avatar']}" alt="{$mybb->user['username']}" class="avatar">.


RE: How do I get user avatar on the index? - mrnu - 2015-02-16

Your code should work really.

This is how you do this in MyBB in a proper way. Firstly you need to generate avatar in PHP.
$useravatar = format_avatar(htmlspecialchars_uni($mybb->user['avatar']), $mybb->user['avatardimensions'], my_strtolower('100x100'));

Then this is a template code.
<img src="{$useravatar['image']}" alt="" {$useravatar['width_height']} />

Maybe someone has better solution without meddling with PHP code, but it doesn't look like it. In global.php there's even no "avatar" word.


RE: How do I get user avatar on the index? - Firelad - 2015-02-16

(2015-02-16, 04:22 PM)mrnu Wrote: This is how you do this in MyBB in a proper way. First you need to generate avatar in PHP.

$useravatar = format_avatar(htmlspecialchars_uni($mybb->user['avatar']), $mybb->user['avatardimensions'], my_strtolower('100x100'));

Then this is a template code.

<img src="{$useravatar['image']}" alt="" {$useravatar['width_height']} />

Maybe someone has better solution without meddling with PHP code, but it doesn't look like it. In global.php there's even no "avatar" word.

This probably can work. I'll test it out for you.
EDIT: That isn't even working.


RE: How do I get user avatar on the index? - expat - 2015-02-16

top one is working, was moving JS around and for some reason it stopped working


RE: How do I get user avatar on the index? - Eldenroot - 2015-02-16

I recommend this
https://github.com/tommm/flpavatar

Fully working solution with cache