General Discussion > Web Development and Site Suggestions

SMF Issue

(1/4) > >>

Nakatre Read:
Running a SMF board as well, and I was wondering if anyone knew how you display your avatar next to the "Hello, Nakatre Read" thing at the top? Is it theme-specific or is there an option or codeline for it somewhere?

Thanks in advance!

Havohej:
That's theme specific; most themes are set up to display the avatar there, but some themes are designed with a more 'sleek' look in mind and leave that snippet of code out.

The bit of code is usually found in index.template.php and will look like this:


--- Code: ---if (!empty($context['user']['avatar']))
echo '
<div id="db-avatar">'.$context['user']['avatar']['image'].'</div>';
--- End code ---

Typically, that area of the main index page is called the "User Area".  For Backstage's default theme, the user area looks like (pay attention to the //commented lines):


--- Code: ---<div id="userarea">';
if (!empty($context['user']['avatar']))
echo '
<div id="db-avatar">'.$context['user']['avatar']['image'].'</div>';

if ($context['user']['is_logged'])
{
echo '
<ul>
<li><b>', $txt['hello_member'], ' ', $context['user']['name'],'</b></li>';

// Only tell them about their messages if they can read their messages!
if ($context['allow_pm'])
echo '
<li>' ,$txt[152], ' <a href="', $scripturl, '?action=pm">', $context['user']['messages'], ' ', $context['user']['messages'] != 1 ? $txt[153] : $txt[471], '</a>', $txt['newmessages4'], ' ', $context['user']['unread_messages'], ' ', $context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1'],'</li>';

// Is the forum in maintenance mode?
if ($context['in_maintenance'] && $context['user']['is_admin'])
echo '
<li><b>', $txt[616], '</b></li>';

// Are there any members waiting for approval?
if (!empty($context['unapproved_members']))
echo '
<li>', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '</li>';

echo '
<li><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a></li>
<li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>';
echo '
</ul>';
}

// Otherwise they're a guest - this time ask them to either register or login - lazy bums...
else
{
echo '
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/sha1.js"></script>
<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '"  style="margin: 0px 0;"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
<b>Username: </b><br />
<input class="loginput" type="text" name="user" size="17" /><br/>
<b>Password: </b><br />
<input class="loginput" type="password" name="passwrd" size="17" />
<input class="logbutton" type="submit" value="', $txt[34], '" /><br /><td valign="middle" align="left">
<label for="cookieneverexp"><b>', $txt[508], ': </b>
<input type="checkbox" name="cookieneverexp" id="cookieneverexp" checked="checked" class="check" /></label>
</td>
<input type="hidden" name="hash_passwrd" value="" />
</form>';
}



echo '
</div>
--- End code ---

Dunno how familiar you are with this stuff (I'm a novice myself, really), but in php (probably other languages too), beginning a line with // tells the browser to ignore that line.  Any time you see a // it's a developer's comment for the information of anyone who looks at the code later to know wtf they're looking at, if needbe.  Even though most of the User Area doesn't have anything to do with the avatar, I left it in just to illustrate the way it's arranged in the index.template.php file.

In this case, some of the sections of that code block are pretty self-explanatory:

if (!empty($context['user']['avatar'])) is pretty clearly saying if a user has an avatar, so by context we can infer that the next bit of code is for displaying the avatar.

if ($context['user']['is_logged']) obviously is checking to see if they're logged in and if so, the following code calls for the "Hello Nakatre", etc.

These SMF templates (most of them) are pretty modular in the way the code is arranged; you might even be able to just copy/paste the avatar code snippet above and insert it into your forum's index.template.php right before the 'logged in?' check.  It goes without saying, though, any edit you make (no matter how small), backup that file first so if you break it you can just re-upload a working file and everything's okay again.

Nakatre Read:
Okay that helped a lot. I found the piece of code in the index.template.php file, and obviously the string of code for the avatar wasn't there at all. Instead of User Area it was called Welcome, though.

But then there was another problem. After inserting the avatar code above the logged in code, the spacing was all wrong. The avatar did show up, but it somehow pushed the "Hello, Nakatre" box away and out of sight.

I'm not really good at PHP at all, so I have no idea what I can do to make it look right.

Havohej:
Hm.. what's the name of your smf theme; I'll download a copy and see if I can figure it out.  In the meantime, search http://www.simplemachines.org/community/index.php for similar help requests - I'm not sure what might cause the avatar piece to push the rest of the user/welcome stuff away like that right off hand.

Nakatre Read:
My SMF theme is caled Overview, from Dzinerstudio

Navigation

[0] Message Index

[#] Next page

Go to full version