I did it with php 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 = "<ul>"; $activePage = ""; foreach($pages as $key=>$val) { if($val['link']==$active) { $res.= "<li><a href='".$val['link']."' class='active' >".$val['name']."</a></li>"; } else { $res.= "<li><a href='".$val['link']."'>".$val['name']."</a></li>"; } } $res.="</ul>"; return $res; }
And then to call this function
echo createTopNav("about");
and the conclusion will be like
<ul> <li><a href="index">Home</a></li> <li><a href="smartphone">Smartphone</a></li> <li><a href="tablet">Tablet</a></li> <li><a href="about" class="active">About Us</a></li> <li><a href="contact">Contact Us</a></li> </ul>
Angela taylor
source share