How to make the parent menu get selected in multi level menu.
For example we have following multilevel menu:
Menu1
Menu2
- Menu2.1
- Menu2.2
-- Menu2.2.1
-- Menu2.2.2
Menu3
-Menu3.1
I generated the above menus from db table of following structure
id | parent_id|title
using recursive method.
I would like to know the logic of how to put some class(say class="active") in the parent level
menus if its child is selected
For example if Menu2.1 or Menu2.2.1 or any child menus is clicked then Menu2 should be selected.
if Menu3.1 is clicked then Menu3 should be selected.
(Note: the page is reloaded when clicked on the menu links)
Thanks in advance for any valueable suggestions/hints/logic.
How to make the parent menu get selected in multi level menu
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: How to make the parent menu get selected in multi level menu
Well if those menu links lead somewhere then you can (or should) have some code to determine which page to show.
If menu 2 = Shoes category then in your menu you can use a conditional statement to determine which menu is selected e.g.
This is one way. Depends how you've structured your site though and how dynamic it is.
You can find JS scripts that do it well.
If menu 2 = Shoes category then in your menu you can use a conditional statement to determine which menu is selected e.g.
Code: Select all
if($_REQUEST['category'] == "shoes"){ echo'class="active"'; } //this would go inside an <li> tag or something.
You can find JS scripts that do it well.
Re: How to make the parent menu get selected in multi level menu
I dont think this will work in multilevel menu.
Sorry aceconcepts i dont think your method works.
Suppose if i have Menu3.1 in the url then only Menu3.1 gets selected. But i want its parent gets selected.
anyway thanks.
Sorry aceconcepts i dont think your method works.
Suppose if i have Menu3.1 in the url then only Menu3.1 gets selected. But i want its parent gets selected.
anyway thanks.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: How to make the parent menu get selected in multi level menu
It will work, it just depends how you code your site.
Either way there are lots of other ways to do it. Take a look at JavaScript.
Either way there are lots of other ways to do it. Take a look at JavaScript.
Re: How to make the parent menu get selected in multi level menu
obviously .aceconcepts wrote:It will work, it just depends how you code your site.
Either way there are lots of other ways to do it. Take a look at JavaScript.
But the concept that you have provided only works for parent level categories but when clicked on child level then it fails.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: How to make the parent menu get selected in multi level menu
Like i said it depends how you code your site. CSS is very flexible if you know how to use it correctly.