MyBB Community Forums

Full Version: Default avatar not showing up
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
[Image: 705706Capture.png]

Hi everyone, 

So here is my problem, I have the default_avatar.gif and another .png version of it also. But it's not showing up... As a grasphist I don't like a broken picture on my Forum  Dodgy

Here is the link to it : http://www.les-as-du-web.esy.es/
Where is that broken image? Is it in user header welcomeblock?

If I have to be logged in to see it please provide a test account.
(2017-03-31, 10:21 PM)Sharree Wrote: [ -> ]Where is that broken image? Is it in user header welcomeblock?

If I have to be logged in to see it please provide a test account.

I sended you a private message with the informations =)
Ok sec. I'll take a look at it now,

Alright so it seems that in your member_welcomeblock in your header template your avatar code appears like so

<img src="http://les-as-du-web.esy.es/{$mybb->user['avatar']}" height="50" width="50">

Remove your forum url from the src, that is why the image is breaking. The code should be
<img src="{$mybb->user['avatar']}" height="50" width="50" class="header_avatar" >

The reason for the header_avatar class is to make default avatar appear if no avatar is uploaded, so add this script to your header code as well (Source: iAndrew)
<script>
$(document).ready(function() {
//create a default avatar for those without one.
if($('.header_avatar img', this).attr('src') == ''){
$('.header_avatar img').attr('src', "images/default_avatar.png");
}
});
</script>


Let me know if that worked for you.
header_welcomeblock_member
<span style="float:left;"><img src="{$mybb->settings['bburl']}/{$mybb->user['avatar']}" height="50" width="50">&nbsp;</span><div id="paneltext">{$lang->welcome_back} <br> <a href="{$mybb->settings['bburl']}/usercp.php"><img src="images/alphagaming/usercp.png"></img>&nbsp;<strong>{$lang->welcome_usercp}</strong> </a>{$modcplink}{$admincplink} <a href="{$mybb->settings['bburl']}/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}"><img src="images/alphagaming/logout.png" alt="log out"/></img>&nbsp;{$lang->welcome_logout}</a></div><br />

Here is what I have in "header_welcomeblock_member"
Replace
<img src="{$mybb->settings['bburl']}/{$mybb->user['avatar']}" height="50" width="50">

with
<img src="{$mybb->user['avatar']}" height="50" width="50" class="header_avatar" >

And at the very start of your header_welcomeblock_member template code add this
<script>
$(document).ready(function() {
//create a default avatar for those without one.
if($('.header_avatar img', this).attr('src') == ''){
$('.header_avatar img').attr('src', "images/default_avatar.png");
}
});
</script>
<script>
$(document).ready(function() {
//create a default avatar for those without one.
if($('.header_avatar img', this).attr('src') == ''){
$('.header_avatar img').attr('src', "images/default_avatar.png");
}
});
</script>

<span style="float:left;"><img src="{$mybb->user['avatar']}" height="50" width="50" class="header_avatar" >&nbsp;</span><div id="paneltext">{$lang->welcome_back} <br>   <a href="{$mybb->settings['bburl']}/usercp.php"><img  src="images/alphagaming/usercp.png"></img>&nbsp;<strong>{$lang->welcome_usercp}</strong>   </a>{$modcplink}{$admincplink} <a href="{$mybb->settings['bburl']}/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}"><img src="images/alphagaming/logout.png"  alt="log out"/></img>&nbsp;{$lang->welcome_logout}</a></div><br />


So here is what I have, and the result is that it's now an empty white sqare.

Alright if you want the easiest solution without a script let's do this

Remove the SCRIPT code completely

And then take
<img src="{$mybb->user['avatar']}" height="50" width="50" class="header_avatar" >

and replace it with
<img src="{$mybb->user['avatar']}" height="50" width="50" style="background: url(images/default_avatar.png);background-size:50px 50px;">


This is a quick inline style solution, if a user has an avatar uploaded it will overlap the default, if there is no uploaded avatar it will show the default.
Pages: 1 2