A
Anonymous
Guest
I would like to include my nav.php nav bar to all my pages. but I need the links to change based on active page.
css is done and works fine but I am trying to convert this navbar to php to make it easier to work with in the future.
this is my navbar in the nav.php file what do i need to add to it to make it change active links per page it is on
<?php
$index = "topnav";
$contact = "topnav";
$services = "topnav";
$employees = "topnav";
//This line gets the file name without the suffix
$menuLinkid=basename($_SERVER['PHP_SELF'],".php");
if($menuLinkid=="index"){
$index = 'active';
}elseif($menuLinkid=="contact"){
$contact = 'active';
}elseif($menuLinkid == "services"){
$services = 'active';
}elseif($menuLinkid == "employees"){
$employees = 'active';
}
?>
<ul>
<li><a class="<?php echo $index; ?>"href="index.php">Home</a></li>
<li><a class="<?php echo $contact; ?>"href="contact.php">Contact Us</a></li>
<li><a class="<?php echo $services; ?>"href="services.php">Services</a></li>
<li><a class="<?php echo $employees; ?>"href="employees.php">Employees</a></li>
</ul>
css is done and works fine but I am trying to convert this navbar to php to make it easier to work with in the future.
this is my navbar in the nav.php file what do i need to add to it to make it change active links per page it is on
<?php
$index = "topnav";
$contact = "topnav";
$services = "topnav";
$employees = "topnav";
//This line gets the file name without the suffix
$menuLinkid=basename($_SERVER['PHP_SELF'],".php");
if($menuLinkid=="index"){
$index = 'active';
}elseif($menuLinkid=="contact"){
$contact = 'active';
}elseif($menuLinkid == "services"){
$services = 'active';
}elseif($menuLinkid == "employees"){
$employees = 'active';
}
?>
<ul>
<li><a class="<?php echo $index; ?>"href="index.php">Home</a></li>
<li><a class="<?php echo $contact; ?>"href="contact.php">Contact Us</a></li>
<li><a class="<?php echo $services; ?>"href="services.php">Services</a></li>
<li><a class="<?php echo $employees; ?>"href="employees.php">Employees</a></li>
</ul>