Sunday, July 6, 2014

Apply Dynamic Active Class on Current Menu Item php

Given this example url:
http://www.example.com/yourpage.php?s=item1&n=01
$_SERVER['REQUEST_URI'] will give you: 
yourpage.php?q=bogus&n=10
$full_url $_SERVER['REQUEST_URI'];

list($url) = explode("?",$full_url);      // get only file name

now $url will carry only file name.

So in your menu 

<ul>
<li><a href="home.php" class="<?php if($url=="home.php") {echo'active';}?>" >Home</a></li>
</ul>

Now it'll dynamically show the active menu.

Thanks

Total Pageviews