php - Change menu active state on different pages -
i using bootstrap pagination menu on website navigate 1 page page.
i copied pagination menu :
http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_pagination_active&stacked=h , added pages of website .
it's works fine , can set active status using:
<li class="active"> <a href="pages/1.php">1</a></li>
according page link code is.
for reasons ,i want have 1 menu file , include pages .
is there way automatically add ".active" class links in included menu?
menu.php
<ul class="pagination"> <li><a href="pages/1.php">1</a></li> <li><a href="pages"pages/2.php">2</a></li> <li><a href="pages/3.php">3</a></li> <li><a href="pages/4.php">4</a></li> </ul>
please help!
you can depending on setup. in javascript, using jquery example:
var currentpage = 2; //say page defined $('.pagination li').eq((currentpage-1)).addclass('active');
if generating pages server side, example in php
$currentpage = 2; $output = '<ul class="pagination">'; //iterating pages if($pagenum == $currentpage){ $output .= <li><a class="active" href="pages/'+$pagenum+'.php">'+$pagenum+'</a></li> } else { $output .= '<li><a href="pages/'+$pagenum+'.php">'+$pagenum+'</a></li>'; } $output .= '</ul>' echo $output;
Comments
Post a Comment