I'm working on putting together a custom PHPTemplate theme for what is largely going to be a static site - the author will mostly be editing it only to update a "news & events" page. I (and he) will not want the login form to be visible to anonymous users on the site, so I'm working on hiding the "$left_sidebar" in the theme so that it's only visible while administering the site.

The tricky part is telling the theme where that is. So far, the best I've been able to come up with is:

  if( (arg(0) == "admin") || ($user_is_logged_in) ) {
    print $sidebar_left;
  } 

Obviously, $user_is_logged_in won't work. What should I have there instead? Or is there a better solution I'm missing?

Thanks in advance.

Comments

nevets’s picture

Since you normally need to be logged to see the admin section you can simplify that to

<?php
  global $user;

  if( $user->uid ) {
    print $sidebar_left;
  }
?> 
sammybaby’s picture

Except that will hide the login form from everyone, won't it? The login form is in the sidebar, the sidebar doesn't print unless you're logged in, and if you're logged in you'll see your menu instead of the form. Sort of a catch 22. :)

webmestre@www.coll-vallcarca.net’s picture

Quote:

"Except that will hide the login form from everyone, won't it? The login form is in the sidebar, the sidebar doesn't print unless you're logged in, and if you're logged in you'll see your menu instead of the form. Sort of a catch 22. :)"

But if you write:
http://localhost/portal/user

You could log on without any problem.

sammybaby’s picture

Aha! Didn't know about the other login form. Thank you. :)

nevets’s picture

To make to only show the login block for people not logged in you could use

<?php
  global $user;
  if( $user->uid ) {
    print $sidebar_left;
  }
  else {
  	$block = user_block('view', 0);
  	print $block['content'];
  }
?>

This way people who are logged in see the left sidebar and people who are not logged in see the login block.