Show menu button ONLY IF logged in

General questions relating to Joomla! There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
jabbamonkey
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Mar 09, 2006 5:46 pm

Show menu button ONLY IF logged in

Postby jabbamonkey » Thu May 04, 2006 5:17 pm

I have a menu I created for my users.  If the user is not registered, I want to show a few menu items (login, register). But if the user is logged in, I want those menu items hidden, and new ones shown (profile, blog, logout).  At the moment, there is an option in the EDIT MENU ITEM that allows me to show items to the PUBLIC, REGISTERED or SPECIAL. But none that show only if NOT registered.

For example, login is one of my menu items. Once the user logs in, I want that menu item hidden. There is no reason for someone logged in to see that link.

I want to avoid using SPECIAL, because all my users will be public (and I dont want to give them AUTHOR access and such).


Can someone tell me how to do this?
Last edited by jabbamonkey on Fri May 05, 2006 12:09 am, edited 1 time in total.

ccoffman
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Fri Dec 02, 2005 5:10 pm

Re: Show menu button ONLY IF logged in

Postby ccoffman » Thu May 04, 2006 5:32 pm

Maybe I am just misunderstanding what you are saying, but you might want to use the Login module instead of a menu link. I think this automatically 'removes' itself after login and turns on the bit which greets the user and the ability to log out.

You could go into the Menu Manager and create a new menu. Then set that to only display if someone is registered.

Hope this helps.

jabbamonkey
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Mar 09, 2006 5:46 pm

Re: Show menu button ONLY IF logged in

Postby jabbamonkey » Thu May 04, 2006 5:40 pm

The menu contains a bunch of items, so using the login module wont work (in fact, it will pull apart the entire top header table I created in my template if I throw the module there).

Basically, if not logged in, I need to show only these:

LOGIN 
REGISTER

If logged in, I need to hide the above, and to show:

PROFILE
BLOG
LOGOUT
(and anything else I add later on)

ccoffman
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Fri Dec 02, 2005 5:10 pm

Re: Show menu button ONLY IF logged in

Postby ccoffman » Thu May 04, 2006 5:47 pm

I would still try the same technique of building a second menu to only display once the visitor has logged in. It seems like that would be the easiest way and the public would still be able to do whatever they are allowed to do.

Wait... duh. I think I see the problem. You are still going to see the original log in menu. Right? Perhaps the log in is only shown on the front page? I know that means whenever they go 'home' they would see it... Wow, this is a bit tougher. Is there no other place you could put the log in module? It seems like you might be needing to do some php coding to get that menu to go away...

If I have any further thoughts / code examples I will pass them along.

camos
Joomla! Ace
Joomla! Ace
Posts: 1056
Joined: Thu Aug 18, 2005 2:39 am

Re: Show menu button ONLY IF logged in

Postby camos » Thu May 04, 2006 6:33 pm

Public is everyone who is not logged in.  The way the ACL works at present there is no way to selectively remove displayed links for accounts that have higher permissions.  Essentially you can restrict up but you cannot restrict down. 

The Login Module is the only easy way to get the Logged In vs Logged Out display.  However there is another way that may suit your needs.  Create a manual link in the template using the Log In/Log Out PHP code.  This is something I did on a Website and it works just fine however I have explained it before and some people could not get it to work for reasons that I could not sort out.  Probably due to the fact that I am not a coder just a manipulator.

This is the code in my template:

Code: Select all

<td > 
<?php
if   ($my->id) {
   echo ( "Logged in: "); ?> <?php echo $my->username;?>
   <?php echo ("<a href='".sefRelToAbs('index.php?option=logout')."'>(Log OUT) </a>");?>
   <?php
   }
 else {
    ?>
<?php echo ("<a href='".sefRelToAbs('index.php?option=com_login')."'>LogIn </a>");?>
<?php   }
?>
</td>


Failing this method it will be necessary to adapt your template layout to manage the Login Module and the Menu Module, probably the User Menu, in a column so they can appear as one.

Cheers
Freedom is not free!
It is however Open Source.

jabbamonkey
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Mar 09, 2006 5:46 pm

Re: Show menu button ONLY IF logged in

Postby jabbamonkey » Thu May 04, 2006 6:35 pm

Cool. That's a good solution. I'll try this. Thanks.

jabbamonkey
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Thu Mar 09, 2006 5:46 pm

Re: Show menu button ONLY IF logged in

Postby jabbamonkey » Fri May 05, 2006 12:08 am

Here's what I did and it works great. Shows the LOGIN if they are not logged in. And shows my REGISTERED "usermenu" when they are logged in...

Code: Select all

<?php
if   (!$my->id)
   {
       ?><span class="mainlevel-usermenu"><a href="<?php echo sefRelToAbs('index.php?option=com_login'); ?>">LOGIN</a></span><?php   
   }
?>
<?php mosLoadModules ( 'usermenu', -1); ?>

sethp
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Jan 16, 2006 8:35 pm

Re: Show menu button ONLY IF logged in

Postby sethp » Thu May 25, 2006 3:44 pm

That's a great tip for showing the "logout" link only to registered users.

Does anyone know how to do this if you're using the SMF Bridge registration? The standard logout link there requires a session ID, so I don't know how to statically code the "logout" link in my template:

Code: Select all

index.php?option=com_smf&Itemid=26&action=logout&sesc=c27f4ed35da32659e3d5f446d17c4d53

allegrande
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Fri Mar 31, 2006 11:50 am

Re: Show menu button ONLY IF logged in

Postby allegrande » Thu Sep 21, 2006 10:24 am

one question..
What file should I edit and where should put in the code above?

thx

allegrande
Joomla! Apprentice
Joomla! Apprentice
Posts: 43
Joined: Fri Mar 31, 2006 11:50 am

Re: Show menu button ONLY IF logged in

Postby allegrande » Thu Sep 21, 2006 11:05 am

camos wrote: Create a manual link in the template using the Log In/Log Out PHP code. 


Could you please explain what file or where to put the code? thx

zs
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Fri Sep 08, 2006 1:42 pm

Re: Show menu button ONLY IF logged in

Postby zs » Mon Jul 02, 2007 12:36 pm

In what file did you do this?
Zev

jabbamonkey wrote:Here's what I did and it works great. Shows the LOGIN if they are not logged in. And shows my REGISTERED "usermenu" when they are logged in...

Code: Select all

<?php
if   (!$my->id)
   {
       ?><span class="mainlevel-usermenu"><a href="<?php echo sefRelToAbs('index.php?option=com_login'); ?>">LOGIN</a></span><?php   
   }
?>
<?php mosLoadModules ( 'usermenu', -1); ?>



Return to “General Questions - 1.0.x”

Who is online

Users browsing this forum: No registered users and 8 guests