Wednesday, February 20, 2013

Active header menu link.

Menu active link with php.

Create menu_link.php and include in all the pages.

$present_page=$_SERVER['PHP_SELF'];
$slice_=explode('/',$present_page);
//getting the max array value key ( start with 0 so need add -1 )
$count_num=(count($slice_)-1);
$act_page=$slice_[$count_num];

$log_in=array('link1'=>'link1.php','link2'=>'link2.php');
<ul>
<?php
foreach($log_in as $keyin=>$linkin)
{
?>
<li><a href="<?php echo $linkin;?>" id="<?php echo $keyin;?>" class="<?php echo ($act_page==$linkin)?'act_menu':''; ?>"><?php echo $keyin;?></a></li>
<?php
}
?>
</ul>

Active page link will be styled with act_menu .
stylesheet : .act_menu {fotn-weigt:bold;color:green;}


No comments:

Post a Comment