navigation - php nav bar active
Hi im trying to make my nav bar button active so it looks different when it is on that specific page.
when i manually change my li class to active it works but when i use my code below to do it the class stays at none.
<?php
echo '<ul >';
echo ($PHP_SELF == '/index.php') ?
'<li ><a href="index.php">Home</a></li>' :
'<li ><a href="index.php">Home</a></li>';
echo ($PHP_SELF == '/how-it-works.php') ?
'<li ><a href="how-it-works.php">How it works</a></li>' :
'<li ><a href="how-it-works.php">How it works</a></li>';
echo ($PHP_SELF == '/gas.php') ?
'<li ><a href="gas.php">Gas</a></li>' :
'<li ><a href="gas.php">Gas</a></li>';
echo ($PHP_SELF == '/electric.php') ?
'<li ><a href="electric.php">Electric</a></li>' :
'<li ><a href="electric.php">Electric</a></li>';
echo ($PHP_SELF == '/telecoms.php') ?
'<li ><a href="telecoms.php">Telecoms</a></li>' :
'<li ><a href="telecoms.php">Telecoms</a></li>';
echo ($PHP_SELF == '/services.php') ?
'<li ><a href="services.php">Services</a></li>' :
'<li ><a href="services.php">Services</a></li>';
echo ($PHP_SELF == '/contact.php') ?
'<li ><a href="contact.php">Contact</a></li>' :
'<li ><a href="contact.php">Contact</a></li>';
echo '</ul>';
?>
so what i want is when im on the index page for the class to be active, and when im not on the index page i want the class to be none
Answer
Solution:
try to use the server variable of PHP http://php.net/manual/en/reserved.variables.server.php
that will work i think
Answer
Solution:
remove all "/" and use $_SERVER['PHP_SELF'].