Page 1 of 1

Hiding 1 single menu item after logging in

Posted: Tue Mar 23, 2010 9:04 am
by Lethyl
Hi,

i have searched the forums for this solution and found a couple of threads but none of them seem to have a solution for them.

I simply want to hide 1 menu item after a user logs in. Is this possible?

Thanks

Re: Hiding 1 single menu item after logging in

Posted: Tue Mar 23, 2010 10:28 am
by Lethyl
I found the solution here: http://www.dart-creations.com/joomla/jo ... ed-in.html

Edit your index.php file of your template and stick this code in somewhere.

Code: Select all

<?php
$user =& JFactory::getUser();
if( !$user->guest ) ?>
<style type="text/css">
.item10 { display:none; }
</style>
<?php endif; ?>
replace the 10 in .item10 with the id of the menu item.

NOTE: this only works on the menu if the menu's module is set to 'List'. If you are familiar with CSS you can use it / extend for the style of any menu item you choose
This didn't initially work for me because I got a Parser error but then one of the users commented below to add the semi-colon after the IF statement like this:

Code: Select all

if( !$user->guest ) : ?>
And this worked brilliantly. Now I remove Menu items whenever I need to and it's great!

Re: Hiding 1 single menu item after logging in

Posted: Sat Apr 17, 2010 12:25 pm
by danjel
I couldn't get it to work, got parsererror every time, even after adding the ";" as suggested.

I changed the code to:

Code: Select all

<?php
// Disable some menuitems
$user =& JFactory::getUser();
if ( !$user->guest ) {
echo '<style type="text/css">';
echo '.item10 { display:none; }';
echo '</style>';
}
?>
This worked for me....
/Danjel

Re: Hiding 1 single menu item after logging in

Posted: Fri Nov 05, 2010 12:25 pm
by LAMF
This didn't work for me...

is this code line

Code: Select all

if ( !$user->guest ) {
guest is that for all registered users or should I use registered instead of guest?

Re: Hiding 1 single menu item after logging in

Posted: Fri Nov 05, 2010 12:40 pm
by danjel
That line tells "if user is not guest - then hide item"
That means that the item will go away when the user has logged in.

If you want to hide the item for guests you should use the permission features in joomla instead.

:-)
Danjel

PS:
Look here:
http://www.danjel.dk/index.php/webcodin ... ng-in.html

Re: Hiding 1 single menu item after logging in

Posted: Fri Nov 05, 2010 12:57 pm
by LAMF
Ok I see but I still doesn't get it working.
I have tried to paste the code both in the <head>..</head> and in the body but no luck...

Re: Hiding 1 single menu item after logging in

Posted: Fri Nov 05, 2010 2:36 pm
by danjel
Have you remembered to change
echo '.item10 { display:none; }';
So that the ".item10" is corrected to the right value ?
/Danjel

Re: Hiding 1 single menu item after logging in

Posted: Fri Nov 05, 2010 6:51 pm
by LAMF
My menu item is item10 so there's no need to change it ;D

But still no luck.

Re: Hiding 1 single menu item after logging in

Posted: Fri Nov 05, 2010 8:09 pm
by Markstein
You could also use MetaMod to hide a menu module when logged in:

http://extensions.joomla.org/extensions/3391/details

You'll basically have 2 menus. One for Guests and one for registered. Refer to this post:

http://forum.joomla.org/viewtopic.php?f=32&t=318325

Mark

Re: Hiding 1 single menu item after logging in

Posted: Sun Nov 07, 2010 7:21 pm
by LAMF
Ok, I almost solved by using the php code + an extra menu that I defined in the template index.php and the templatedetails.xml.
I also had to change the new menu with list property as told in the thread.
Then use two menu items one "Login" for public views and "Logout" for logged in.
With the php hack it hides the Login link and only displays the Logout so it's kind of solved.

I would like the Log out link to be e direct log out link not having to point it to a log out page.
How do I do that?

Re: Hiding 1 single menu item after logging in

Posted: Sun Nov 07, 2010 8:09 pm
by mark_up
Hi Lamf,

YOu can't do that with just a link, not easily anyway. It expects a form submission, and having a form around your main menu is not something to be done lightly.

CHeers,
Mark

Re: Hiding 1 single menu item after logging in

Posted: Mon Nov 08, 2010 6:27 am
by LAMF
mark_up wrote:Hi Lamf,

YOu can't do that with just a link, not easily anyway. It expects a form submission, and having a form around your main menu is not something to be done lightly.

CHeers,
Mark
Hi Mark,
Ok but how is it possible that for example this forum has a Logout link where you just have to click the link and voila you'e logged out?
And for example the URL fo that link is: http://forum.joomla.org/ucp.php?mode=logout

Re: Hiding 1 single menu item after logging in

Posted: Mon Nov 08, 2010 6:51 am
by mark_up
This forum is not Joomla. It's phpBB :)

Re: Hiding 1 single menu item after logging in

Posted: Mon Nov 08, 2010 10:01 am
by LAMF
Yeah I know but why then isn't a "simple" thing as a direct logout link/button possible?
I'm not addressing this to you mark_up just to anyone in orer to maybe solve this "simple" task.

Re: Hiding 1 single menu item after logging in

Posted: Wed Jul 06, 2011 10:07 pm
by Alli_sun
This is the code that worked for me. I placed this code at the end of the index.php file.

Code: Select all

?>

<?php
// Disable some menuitems
$user =& JFactory::getUser();
if ( !$user->guest ) {
echo '<style type="text/css">';
echo '.item10 { display:none; }';
echo '.item11 { display:none; }';
echo '</style>';
}
?>
Note: I had to add a "?>" at the end of the existing code to prevent getting an error returned when adding the new code.

I'm using joomla 1.5.23

Re: Hiding 1 single menu item after logging in

Posted: Fri Jul 15, 2011 7:44 pm
by jthrongard
OMG, that's brilliant! Why is this thread buried so deep. This really needs to be developed into a plugin!!!

Re: Hiding 1 single menu item after logging in

Posted: Thu Oct 20, 2011 11:27 am
by furnicav
I had this issue also on one of my websites. I've used @Alli_sun code and works. Thanks a lot!

Re: Hiding 1 single menu item after logging in

Posted: Sun Nov 06, 2011 10:43 pm
by deanholdway
ive also used @Alli_sun code and works fine

Re: Hiding 1 single menu item after logging in

Posted: Fri Feb 03, 2012 9:37 pm
by LAMF
Alli_sun your code works.
Now this can be done in 1.7 and above but if you don't want to go up to 1.7-2.5 this solution is the best!