Adding a Custom Login Box for Drupal 7

I want to have a small login box in the top left corner the web site.

When the user is logged in, I want to show the secondary menu instead.

There are several steps to this.

First, in your theme/templates/page.tpl.php file add this code

uid ) { // Logged in user print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'inline', 'clearfix'), ), 'heading' => array('text' => $secondary_menu_heading, 'level' => 'h2', 'class' => array('element-invisible'), ), )); } else { // Not logged in $block = module_invoke('user', 'block_view', 'login'); unset($block['content']['links']); // removes the register, etc.. link print render($block); } ?>

This invokes the login block.

Now we need to reformat the CSS. Add the following to any active stylesheet (eg navigation.css).

#user-login-form label {
    display: inline;
    font-weight: normal;
}
#user-login-form .form-item {
    display: inline;
}
#user-login-form .form-actions {
    display: inline;
}
#user-login-form .form-text {
    width: 100px;
}

And it is done!

Leave a Reply

Your email address will not be published. Required fields are marked *