I'm having issues with the use of php to control if a navigation link is given the class "active" depending on what the $CURRENT_PAGE variable is set to.
Here is the navigation.php file that is included into every website page file.
<div class="container mt-3">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link <?php if ($CURRENT_PAGE == "Index") {?>active<?php }?>" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link <?php if ($CURRENT_PAGE == "About") {?>active<?php }?>" href="about.php">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link <?php if ($CURRENT_PAGE == "Contact") {?>active<?php }?>" href="contact.php">Contact</a>
</li>
</ul>
</div>
Here is the config file that sets the $CURRENT_PAGE variable:
<?php
switch ($_SERVER["SCRIPT_NAME"]) {
case "/php-template/about.php":
$CURRENT_PAGE = "About";
$PAGE_TITLE = "About Us";
break;
case "/php-template/contact.php":
$CURRENT_PAGE = "Contact";
$PAGE_TITLE = "Contact Us";
break;
default:
$CURRENT_PAGE = "Index";
$PAGE_TITLE = "Welcome to my homepage!";
}
?>
For reference of my template, I am using the source code template from this post. https://medium.com/@stevesohcot/sample-basic-php-template-for-file-structure-with-example-code-47ff6d610191
Regarding the problem I am having, the active class is only showing up on the home link, even when I am on a different page such as the contact page. When I hover over the nav links 'about', and 'contact', the active class initiates, but only initiates when I hover over either of the 'about' and 'contact' nav links. Maybe this has to do with the bootstrap classes I am using?