Thursday, 9 October 2014

Highlight current menu item in PHP



Useful snippet for highlight current menu item in PHP
<ul class="sub-nav" > 
<?php
 $full_name = $_SERVER['PHP_SELF'];
 $name_array = explode('/',$full_name); 
$count = count($name_array); 
$page_name = $name_array[$count-1];
 ?> 
 <li>
              <a class="<?php echo ($page_name=='where-to-buy.php')?'active':'';?>" href="where-to-buy.php">WHERE TO BUY</a>
</li> 
<li>
            <a class="<?php echo ($page_name=='about.php')?'active':'';?>" href="about.php">ABOUT US</a>
</li> 
 <li>
                    <a class="<?php echo ($page_name=='contact.php')?'active':'';?>" href="contact.php">CONTACT US</a>
</li> 
 
</ul>

0 comments:

Post a Comment