How to set current page “active” in php

后端 未结 17 1837
栀梦
栀梦 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:53

    Better late than never - I like to keep it simple, to be honest, especially if there's a ton of scripting and PHP going on.

    I place this code on the top of each page to identify the page:

    
    

    Then your menu/navigation (mine is bootstrap 4) looks like this:

    
    

    I'm not saying this is the optimal method, but it works for me and it's simple to implement.

提交回复
热议问题