Hiding Menu item after logging in
- Details
- Parent Category: Webcoding
- Category: Joomla
- Last Updated on Monday, 15 November 2010 19:13
- Published on Wednesday, 19 May 2010 22:27
- Written by Administrator
- Hits: 8432
On a Joomla! site I wanted to hide a menu item after a person logged in.
It was a memberlist, that had the same menu title, but the content should be changed to something more detailed after the user had logged in.
My solution was to create 2 menu items with the same text, but different aliases, this is important if you have seo enabled, otherwise I have not found it important.
The first item was marked as "Registered" in "Access level", this menu item contains the most information, specifically the information that should not be visible to the public.
Remember to set this restriction on both the menu item, and the target (in my case a "Contact Category Layout").
The second menu item are created as a standard public page.
Note the "ItemID" at the very right.
Now find and open your index.php file and insert this somewhere, I did it at the top, so that it\'s easy to locate again:
Also I selected the index.php file located in my template fodler, so that future updates will not revert the change.
<?php
// Disable some menuitems
$user =& JFactory::getUser();
if ( !$user->guest ) {
echo \'<style type="text/css">\';
echo \'.item10 { display:none; }\';
echo \'</style>\';
}
?>
Change the "10" in ".item10" to the ItemID you found earlier, note the ItemID 2 is ".item2" not ".item02".
Upload the index.php file again, and the menu item should be gone when logged in.
Happy coding :-)
Danjel