I've got a wee problem. I know from answers such as this how to have an active
link on the navigation bar.
However, this doesn't work if there are GET variables after the link. So while my <li>
gets class = "active"
if I load daily.php
, it doesn't get the class if I load daily.php?project=4
.
The code I am using right now for the navigation bar and making a certain link active is this:
<?php
function echoActiveClassIfRequestMatches($requestUri)
{
$current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
if ($current_file_name == $requestUri)
echo 'class="active"';
}
?>
<div id="menu">
<ul>
<li <?php echoActiveClassIfRequestMatches("daily") ?>><a href="daily.php">Daily</a></li>
<li <?php echoActiveClassIfRequestMatches("weekly") ?>><a href="weekly.php">Weekly</a></li>
<li <?php echoActiveClassIfRequestMatches("monthly") ?>><a href="monthly.php">Monthly</a></li>
</ul></div>
As I said, this doesn't work if instead of daily.php
I load daily.php?project=4
.
All help is welcome, and if you need any more code, please just ask!
Thank you very much.