Hi,

I'm trying to display a block on the homepage for logged in users. I've done this using mini panels but would like to display something like "Welcome (USER)". I can't seem to do this in the panel settings so can I create a block that gets the username of the currently logged in user using PHP to display on the homepage?

Any help is appreciated.

Comments

arh1’s picture

in your theme, you can do this easily with the $user object.

e.g. add something like this to page.tpl.php:

<?php
if ($user->uid) {
  print 'Welcome '.$user->name.'!';
}
else {
  print 'Welcome, Guest!';
}
?>
Jboo’s picture

Thanks for the reply. What I need to do is insert it using blocks and couldn't get this to work at first. However, I altered it slightly so it works now, but is this correct?

<?php
global $user;
if ($user->uid) {
  print 'Welcome back '.$user->name.'!';
}
?>

Thanks for your help.

My new EasySnoozing, Nursing and BusinessEgghead websites on D7!

sankarsvks88’s picture

Go to Structure->Block->Add block.

Give block title->block description>Block Body. copy this code and paste it and change the "Text format" to the format which supports Php code.

Done!

werlincorp’s picture

How I do it in Garland Theme? instead of display the username i want to display Full name ie; Hi, Full Name ... i also created field in profiles.. called profile_fullname

Suyash Pancholi’s picture

Thank You so Much it's working