Skip to content Skip to sidebar Skip to footer

Highlight Current Page On Dynamic Navigation Php

I get my dynamic navigation menu from the database because I have a CMS, so here's my code:

    Solution 1:

    u can try the following code

    <?php$currentpage = $_SERVER['REQUEST_URI'];?><ul><?php$result = mysql_query("SELECT id, name, DESCRIPTION FROM menu where VISIBLE='1' ORDER BY
     `order` ASC") ordie(mysql_error()); 
    
    while($row = mysql_fetch_array($result))
    {
     ?>
    <li<?phpif(preg_match("/index/i", $currentpage)||($currentpage=="/")) { echo" 
    class='active'";     } ?>><ahref="index.php">Home</a></li><?
     }
    ?>

    instead of index you can also write $row[name] in a variable and replace /index/i with it

    Solution 2:

    set a variable on the page like

    $navlink = '<somevalue>'

    and check the the value in li

    <li<?phpif($navlink == '<somevalue>') {echo"class='active'"}?>>

    i think it will work.

Post a Comment for "Highlight Current Page On Dynamic Navigation Php"