How to create a login/logout/user links menu
You want to manage the user login!
You want to show the user name and create a link to the user profile. Use the following code in your page template to create a div that changes content depending on the user login status. Remember to flush the template cache.
<div id="user-links" class="clear-block">
<?php // Login/logout
if (!$user->uid) {
print l("Log in", "user/login");
}
elseif ($user->uid) {
print ' Welcome <a href="/user">'.$user->name.'</a> | '.l("Log out", "logout");
}?>
</div>
To have primary links aligned left and the user links on the right on a menu bar use the following code. Styles should be in the CSS file but are shown here for simplicity.
<?php if (!empty($primary_links)): ?>
<div id="primary" class="zzzclear-block" style="float: left">
<?php echo theme('links', $primary_links, array('class' => 'links primary-links')); ?>
</div>
<div id="user-links" class="clear-block" style="float: right; margin-right: 10px;">
<?php // Login/logout
if (!$user->uid) {
print l("Log in", "user/login");
}
elseif ($user->uid) {
print ' Welcome <a href="/user">'.$user->name.'</a> | '.l("Log out", "logout");
}?>
</div>
<div style="clear: both"> </div>
<?php endif; ?>
- Login to post comments