How to set current page “active” in php

后端 未结 17 1902
栀梦
栀梦 2020-12-02 21:38

Hi I have a menu on my site on each page, I want to put it in it\'s own menu.php file but i\'m not sure how to set the class=\"active\" for whatever page i\

17条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 22:09

    Simplere solution:

    Borrowing the code from asprin above;

    Create a new file menu.php where you will store the one and only copy of the menu. In this file, you will create a function addMenu($pageName) that take a parameter as the page name and returns a string consisting of the menu after having added the current tag.

    In your HTML code, you would include(menu.php) and then call the function addMenu with the current page name. So your code will look like this:

    menu.php

         
                        
  • Öffnungszeiten
  • Sauna
  • Frauensauna
  • Beauty Lounge
  • Feiertage
'; return $menu; } ?>

And in your HTML, say this:


提交回复
热议问题