MyBB Community Forums

Full Version: Avatars in Header (template conditionals)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
(I have the Template Conditionals plugin installed)

I have modified my header template such that it displays a user's avatar on the left side of the forum logo. (along with a couple other modifications, shown below)

header template:

<div id="container">
		<a name="top" id="top"></a>
		<div id="header">
			<div class="logo">

<a href="{$mybb->settings['bburl']}/">
<img src="{$mybb->user['avatar']}" width="75px" height="75px" /><img src="{$theme['logo']}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a>

<span style="float:right">

<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.alonelylife2.com%2F&amp;send=false&amp;layout=button_count&amp;width=80&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:21px; allowTransparency="true"></iframe>			
<iframe allowtransparency="true" frameborder="0" scrolling="no" src="https://platform.twitter.com/widgets/tweet_button.html" style="width:90px; height:20px;"></iframe>

<a href="/chatroom.html" target="_blank"><img src="/images/chat.png" border="0px"/></a></span>
</div>
<div class="menu">
				<ul>

					<li><a href="{$mybb->settings['bburl']}/search.php"><img src="{$theme['imgdir']}/toplinks/search.png" alt="" title="" />{$lang->toplinks_search}</a></li>
					<li><a href="{$mybb->settings['bburl']}/memberlist.php"><img src="{$theme['imgdir']}/toplinks/memberlist.png" alt="" title="" />{$lang->toplinks_memberlist}</a></li>
					<li><a href="{$mybb->settings['bburl']}/misc.php?action=help"><img src="{$theme['imgdir']}/toplinks/help.png" alt="" title="" />{$lang->toplinks_help}</a></li>
				</ul>
			</div>
			<hr class="hidden" />
			<div id="panel">
				{$welcomeblock}
			</div>
		</div>
		<hr class="hidden" />
		<br class="clear" />
		<div id="content">
			{$pm_notice}
			{$bannedwarning}
			{$bbclosedwarning}
			{$unreadreports}
			{$pending_joinrequests}
			<navigation>
			<br />

What I want to do now is be able to display a different image (in place of the avatar) for two different groups of people:

1. Guests (call this by group ID?)
2. Registered Members (call this in similar fashion as seen below?)

I am already doing something similar in the postbit and postbit_classic templates, like this (credit to Leefish):

<if $post['avatar'] then>
{$post['useravatar']}
<else><img src="{$mybb->settings['bburl']}/images/avatars/default.png" alt="avatar" height="125px" width="125px" />
</if>

Any ideas how I can accomplish this? Basically I want guests (as a group) and registered users with no avatar (as a group - if possible) to see a default image (default.png) in that space next to the logo.
PHP and Template Conditionals plugin accepts basically any variable, so to accomplish your target you might use the following piece of code:

<if $GLOBALS['mybb']->user['usergroup'] == 1 then>

code goes here

</if>

Where '1' stands for the GID of your desired usergroup. You may want to use an alternative for guests, not based on usergroup GID:

<if !$mybb->user['uid'] then>

code for guests goes here

</if>
Thank you. That helps me know how to target a specific group by ID.

But how do I target registered members with no avatars?

I would like members with avatars to see a reduced size image of their avatar to the left of the logo.

On the other hand, I would like guests and members (with no avatar) to see an image I choose. How do I accomplish this?
<if !$mybb->user['avatar'] then>
Display to users with no avatar.
</if>
Thanks to both of you for the help, with your guidance and a little perseverance, I got it!

<if !$mybb->user['avatar'] then>

<a href="{$mybb->settings['bburl']}/">
<img src="/images/avatars/defaultavatarheader.png" width="75px" height="75px" alt="Home" />
<img src="{$theme['logo']}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a>

<elseif $mybb->user['avatar'] then>

<a href="{$mybb->settings['bburl']}/">
<img src="{$mybb->user['avatar']}" width="75px" height="75px" alt="Home"/>
<img src="{$theme['logo']}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a>

</if>