Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Show or Hide Menu Item Using CSS

Show or Hide Menu Item Using CSS

Is it possible to display or hide a menu item by using a CSS class?

For example I would like item173 to be visible to guest but when they log in they see item184.

This is what I was using before but this was used for modules.  Thank you.

Code:


if ($user->id > 0) {
  $names = explode(" ", $user->name);
  echo "<b>Welcome, " . htmlentities(@$names[0]) . "</b>"; // don't forget that trailing ";" !!
  return 130; // show logout module to all these logged in users
}
return 103; // show login module to all guests

MyWorld
Beginner Modder
ranks
useravatar
Offline
14 Posts
Administrator has disabled public posting

Re: Show or Hide Menu Item Using CSS

Hi MyWorld,
The ability to do this depends on the structure of the HTML/CSS for your exact site and template/menu system. Some Joomla templates include the ID of the menu item in the HTML elements for the menu, and in that case there's a good chance you can isolate this with some CSS code that you can insert via PHP code.

If you can take a copy of some of the HTML surrounding and including the menu item that you want to remove, please paste it here and I can help to identify if it's going to be possible that way.

There are some other approaches too.

1 - If the menu is being displayed using the standard Joomla menu module (as opposed to something built in to the template system, often for a main menu), then take a look at ElastiMenu, https://www.metamodpro.com/software/elastimenu
What you can do with that is to set up a 2nd copy of the menu module, using ElastiMenu. In that 2nd copy, use the control in ElastiMenu to "hide" the menu item you need to hide for some users. Now you have 2 modules, 1 with the menu item, and 1 without it. Now you can use MetaMod to include either one or the other depending on login status.

2 - You can use Chameleon to hide individual menu items depending on any criteria you want to, including login status, group, etc. Using that system you don't need Chameleon.

3 - You may be able to avoid 3rd party software entirely by creating a view level that includes non logged in users only. Then you can set item173 to that view level, and item184 to the view level for logged in users.

Cheers
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Show or Hide Menu Item Using CSS

Hi there,

Sorry about the delay.

I took a screen shot of the menu code via firebug but I don't see an option here to add image so this is what it is basically:

li.maximenuck item173 first level1  hoverbgactive (login/register)
li.maximenuck item184 first level1  hoverbgactive (logout)

I am able to hide a menu from users that are not logged in and users that are logged in.  The main reason why I wanted to use MetaMod is because I wanted to display the user's name when they are logged in and this is the only way I think it can be done unless you know of some other way without using a third party software smile

Thanks

MyWorld
Beginner Modder
ranks
useravatar
Offline
14 Posts
Administrator has disabled public posting

Re: Show or Hide Menu Item Using CSS

Ok I see from what you wrote that you are using Maxi Menu CK. One of the things you can do with Maximenuck is to display a module in the menu. So, how about make a module of type MetaMod, that has the following:

echo '<a href="http://www.mysite.com/account">';
$names = explode(" ", $user->name);
echo "<b>Welcome, " . htmlentities(@$names[0]) . "</b>";
echo '</a>';

(obviously, change the link to whatever you want them to land on when they click the greeting)
Then follow the instructions on https://www.joomlack.fr/en/joomla-exten … aximenu-ck for assigning that module into a menu item.
You can also hide/show the menu item by logged in/out status using the normal Joomla mechanisms.

Would that achieve the desired result?

Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Show or Hide Menu Item Using CSS

Perfect. Thank you so much!! Really appreciate it.

MyWorld
Beginner Modder
ranks
useravatar
Offline
14 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Total Posts Today:
1
User Info:
 
Total Users:
10075
Newest User:
rsker57
Members Online:
0
Guests Online:
172

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked