Advertisement

Hiding 1 single menu item after logging in

Need help with the Administration of your Joomla! 1.5 site? This is the spot for you.

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.
Locked
Lethyl
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Mar 22, 2010 9:48 pm

Hiding 1 single menu item after logging in

Post by Lethyl » Tue Mar 23, 2010 9:04 am

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

Advertisement
Lethyl
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Mar 22, 2010 9:48 pm

Re: Hiding 1 single menu item after logging in

Post by Lethyl » Tue Mar 23, 2010 10:28 am

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!

danjel
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Wed Apr 14, 2010 5:11 am

Re: Hiding 1 single menu item after logging in

Post by danjel » Sat Apr 17, 2010 12:25 pm

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

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Fri Nov 05, 2010 12:25 pm

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?

danjel
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Wed Apr 14, 2010 5:11 am

Re: Hiding 1 single menu item after logging in

Post by danjel » Fri Nov 05, 2010 12:40 pm

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

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Fri Nov 05, 2010 12:57 pm

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...

danjel
Joomla! Apprentice
Joomla! Apprentice
Posts: 30
Joined: Wed Apr 14, 2010 5:11 am

Re: Hiding 1 single menu item after logging in

Post by danjel » Fri Nov 05, 2010 2:36 pm

Have you remembered to change
echo '.item10 { display:none; }';
So that the ".item10" is corrected to the right value ?
/Danjel

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Fri Nov 05, 2010 6:51 pm

My menu item is item10 so there's no need to change it ;D

But still no luck.

Markstein
Joomla! Hero
Joomla! Hero
Posts: 2268
Joined: Sat Feb 09, 2008 8:27 am
Location: California, USA

Re: Hiding 1 single menu item after logging in

Post by Markstein » Fri Nov 05, 2010 8:09 pm

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

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Sun Nov 07, 2010 7:21 pm

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?

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Hiding 1 single menu item after logging in

Post by mark_up » Sun Nov 07, 2010 8:09 pm

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
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Mon Nov 08, 2010 6:27 am

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

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Hiding 1 single menu item after logging in

Post by mark_up » Mon Nov 08, 2010 6:51 am

This forum is not Joomla. It's phpBB :)
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Mon Nov 08, 2010 10:01 am

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.

User avatar
Alli_sun
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Jun 08, 2011 4:46 pm

Re: Hiding 1 single menu item after logging in

Post by Alli_sun » Wed Jul 06, 2011 10:07 pm

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

jthrongard
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Mon Mar 08, 2010 4:44 pm
Location: Boise, ID
Contact:

Re: Hiding 1 single menu item after logging in

Post by jthrongard » Fri Jul 15, 2011 7:44 pm

OMG, that's brilliant! Why is this thread buried so deep. This really needs to be developed into a plugin!!!
Small Business Joomla! Website Design - Simple CMS Design
http://www.simplecmsdesign.com

furnicav
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Thu Oct 20, 2011 11:20 am

Re: Hiding 1 single menu item after logging in

Post by furnicav » Thu Oct 20, 2011 11:27 am

I had this issue also on one of my websites. I've used @Alli_sun code and works. Thanks a lot!
Promotii online laptopuri ieftine de la toppromotii.ro

deanholdway
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Nov 04, 2011 11:32 pm
Location: UK
Contact:

Re: Hiding 1 single menu item after logging in

Post by deanholdway » Sun Nov 06, 2011 10:43 pm

ive also used @Alli_sun code and works fine

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Hiding 1 single menu item after logging in

Post by LAMF » Fri Feb 03, 2012 9:37 pm

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!

Advertisement

Locked

Return to “Administration 1.5”