I am currently designing a vertical drop menu (with submenus), here’s how it looks:
Click here to see the screenshot
On the left, no menu item is selected.
On the middle and on the right there are sub-menus opened (and the selected page in blue).
One sub-menu can be opened at once (one opens => the other closes).
The contents of the menu is not dynamic.
The big problem was that when i opened a new page, the sub-menu of the selected page had to be opened.
So I decided that all my pages links will be like index.php?p=my_selected_page and in a file menu.php I built this array:
$menu = array(
'Présentation' => array(
'accueil' => 'Accueil',
'inscription' => 'Inscrivez-vous'
),
'Nos actions' => array(
'mediation-familiale' => 'Médiation familiale',
'droit-de-visite' => 'Droit de visite accompagnée',
'accompagnement-familial' => 'Accompagnement familial'
)
// [...]
);
Then I get the page $_GET ['p']. I look through the array and writes the menu html match.
If $_GET['p'] is one of the key sub-array, I display the sub-menu with a CSS class so that this menu is open.
(And the link is selected by default).
While this solution works, this system only allows me to store links like index.php?p=my_selected_page.
I wish I could put other links, like forum.php (and include menu.php in forum.php), etc..
If you have any ideas to make this possible, I would be grateful.
(I am French. Sorry for spelling mistakes.)
You could use
$_SERVER["SCRIPT_NAME"]to ask for the name of your script file, and then do the verification with that information, not sending a variable via GET. 🙂e.g.
At this point, you will have the filename stored in
$script_file, and you could match it with your array’s keys.Hope this helps.