How to set current page “active” in php

后端 未结 17 1860
栀梦
栀梦 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 21:48

    there is two things you can do.

    first you can read the current filename of the php file you request by using $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] or any other $_SERVER global variables that you can use to read your current page and compare it with the link's url, something like this

      class="activatepage"  >
           Öffnungszeiten
        
    

    the second one is to create a variable that you can read globally that would store the current name of the current page, like this

    
    
    class="activatepage"  >
     Öffnungszeiten
    
    

提交回复
热议问题