Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a class in the navigation menu

Considering the case, that I have the following menu:

<ul>
<li><a href="index.php">Index</a></li>
<li><a href="about.php">About</a></li>
<li><a href="test.php">Test</a><li>
</ul

And the menu is located in header.php . For each page (Index, About, Test), I have index.php, about.php and test.php, and all these files include the header.php !

What I need is adding a class to the li when we are on different pages. So if we are on the about.php, the class should be added on the second li.

Is there any way to do with jQuery, or what are the ways to handle this problem?

like image 717
kk1991 Avatar asked Dec 01 '22 05:12

kk1991


1 Answers

<ul>
<li><a href="index.php" <?php if($_SERVER['PHP_SELF']=="/index.php") echo 'class="someclass"'; ?> >Index</a></li>
<li><a href="about.php" <?php if($_SERVER['PHP_SELF']=="/about.php") echo 'class="someclass"'; ?> >About</a></li>
<li><a href="test.php" <?php if($_SERVER['PHP_SELF']=="/test.php") echo 'class="someclass"'; ?> >Test</a><li>
</ul>

This might not be the best method, but it does the task serverside.

like image 171
hjpotter92 Avatar answered Dec 11 '22 12:12

hjpotter92