开发者

Opening submenu depending on the selected page

开发者 https://www.devze.com 2023-03-17 00:42 出处:网络
I am currently designing a vertical drop menu (with submenus), here\'s how it looks: Click here to see the screenshot

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 $_GE开发者_运维问答T['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.

<?php

$script_file = $_SERVER["SCRIPT_NAME"];
$no_slashes = explode('/', $script_file);
$script_file = $no_slashes[count($no_slashes) - 1]; 

echo $script_file;

?>

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.


Your questions seems very comfusing,you may be can try jquery add some javascript click event. on the other hand, I think if you can use the framework, means inclue all your header

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号