MyBB Community Forums

Full Version: Show username in navigation bar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone!

Recently, I have been messing around with the MyBB 1.7 files so I can find out what I need to change when I upgrade my real forum to MyBB 1.8.

I am trying to get the person's username (if they are logged in) to show in my navbar.

[attachment=28435]

I have the CSS right it's just that whenever I use a hook like {$formattedname} it won't show up.

Does someone know the hook that will show a plain username?

Thanks!
You can put {$mybb->user['username']} in the template where you want it to show up. Hope that helps Smile
@Ferron, Thanks! It worked!

Now what I'm having issues with is the padding of the logout link when you are logged in.

What it looks like for guests:

[attachment=28437]

What it looks like for people logged in:

[attachment=28436]

Can someone please give me the code to get the word logout in the correct place? I'm not sure why it is doing this only for the word logout. As you can see in the pictures above, the login and register words are fitting perfectly.

Thanks!
Hmm...can't tell exactly from the images. Can you post the CSS for the username and logout link?
CSS Wrote:.navbar {
width: 100%;
height: 29px;
background-color: #000;
background-repeat: repeat-x;
font-size: 13px;
}
#membernametop {
background-position: 0 0;
border: 0;
padding: 2.5px 2.5px 2.5px;
padding-right: 10px;
margin: 0;
float: right;
vertical-align: middle;
font-weight: bold;
text-decoration: none;
color: #FFF;
}
#membernametop a:hover {
color#FFF;
}
#membernametop a:link {
color: #ccc
}
#membernametop a:visited {
color: #ccc
}

headerblock_welcome_guest Wrote:<script type="text/javascript">
<!--
lang.username = "{$lang->login_username}";
lang.password = "{$lang->login_password}";
lang.login = "{$lang->login}";
lang.lost_password = "<a href=\"{$mybb->settings['bburl']}/member.php?action=lostpw\" class=\"lost_password\">{$lang->lost_password}<\/a>";
lang.register_url = "<a href=\"{$mybb->settings['bburl']}/member.php?action=register\" class=\"register\">{$lang->welcome_register}<\/a>";
lang.remember_me = "{$lang->remember_me}";
// -->
</script>
<!-- Continuation of div(class="upper") as opened in the header template -->
<div id="membernametop">
<a href="{$mybb->settings['bburl']}/member.php?action=login">Login</a> or <a href="{$mybb->settings['bburl']}/member.php?action=register">Register</a>
</div>
</div>
</div>

header_welcomeblock_member Wrote:<!-- Continuation of div(class="upper") as opened in the header template -->
<div id="membernametop">
&mdash; <a href="{$mybb->settings['bburl']}/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}">Logout</a>
</div>
</div>
</div>
<div class="lower">
<ul class="menu user_links">
<!--<a href="#" onclick="MyBB.popupWindow('{$mybb->settings['bburl']}/misc.php?action=buddypopup', 'buddyList', 350, 350);">{$lang->welcome_open_buddy_list}</a>-->
<a href="{$mybb->settings['bburl']}/search.php?action=getnew">{$lang->welcome_newposts}</a></li>
&bull; <a href="{$mybb->settings['bburl']}/search.php?action=getdaily">{$lang->welcome_todaysposts}</a></li>
&bull; <a href="{$mybb->settings['bburl']}/private.php">{$lang->welcome_pms}</a> {$lang->welcome_pms_usage}</li>
</ul>
</div>

Does this work?
Yep, that works. Thanks for the code Smile

I'm guessing it's because you start a new div for just the logout link. It looks like you have the username in the header template, so try putting it inside the "membernametop" div.
Ok so now it looks ok when you are logged in but for guests, it shows the words login or register exactly like how it showed the logout button before.

Look at the logged in picture in this post.

(So they just switched positions...)

Is there any php code that I need to edit so it only shows the logout button for registered users, members, mods, etc.?
Nevermind, I have solved my problem by using the code from this post as an example. While doing this for the Log Out link, I have also made it so that it shows the User CP link to logged in members and the Register link to logged out members or guests.