How to set current page “active” in php

后端 未结 17 1858
栀梦
栀梦 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条回答
  •  Happy的楠姐
    2020-12-02 22:01

    I have done it with php in this way,

    function createTopNav($active)
    {
        $pages = array(
            array(
                'name'=>'Home',
                'link'=>'index'
            ),
            array(
                'name'=>'Smartphone',
                'link'=>'smartphone'
            ),
            array(
                'name'=>'Tablet',
                'link'=>'tablet'
            ),
            array(
                'name'=>'About Us',
                'link'=>'about'
            ),
            array(
                'name'=>'Contact Us',
                'link'=>'contact'
            )
        );
        $res = "";
        return $res;
    }
    

    And then to call this function

    echo createTopNav("about");
    

    and the output will be like this

    
    

提交回复
热议问题