How to set current page “active” in php

后端 未结 17 1900
栀梦
栀梦 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

    This worked for me:

        function active_page($script){
    
        $actual = basename($_SERVER['PHP_SELF']);
    
      if($script == $actual){
          return 'active-page'; //class name in css
      }
    }
    

提交回复
热议问题