Tuesday, August 17, 2010

Display login/register form below the post content in Drupal

Hi there,
In drupal, When we enabled the comments for blog content type and only registered users can post the comments. If user not logged in then they will see Login or register to post contents at bottom of the post. These links were redirected to a next page to login/register but it is better to display below the post, For this use below code.

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
if($node->type == 'blog'){
case 'view':
global $user;
if($user->uid == 0){ //If not logged in
$node->content['show_login'] = array('#value' => drupal_get_form('user_login_block'),
'#weight' => 99);
This will display the login/register screen at the end of post for anonymous user