Perhaps this might not be the most efficient method, but I'm going to share it anyway.
I utilized PHP, Bootstrap, and Font Awesome in creating my solution.
Basically, I have two pages: 1. index and 2. create-user
Add the following code snippet above your existing code:
<?php
$name=basename($_SERVER["REQUEST_URI"]);
$name=str_replace(".php","",$name);
switch ($name) {
case "create-user":
$a = 2;
break;
case "index":
$a = 1;
break;
default:
$a=1;
}
?>
For the menu functionality, add
<?php if($a==1){echo "active";} ?>
in the class attribute for menu item 1, and for menu item 2, add
<?php if($a==2){echo "active";} ?>
<ul id="menu" class="navbar-nav flex-column text-right mt-3 p-1">
<li class="nav-item mb-2">
<a href="index.php" class="nav-link text-white customlihamid <?php if($a==1){echo "active";} ?>"><i
class="fas fa-home fa-lg text-light ml-3"></i>dashboard</a>
</li>
<li class="nav-item mb-2">
<a href="#" href="javascript:" data-parent="#menu" data-toggle="collapse"
class="accordion-toggle nav-link text-white customlihamid <?php if($a==2){echo "active";} ?>" data-target="#tickets">
<i class="fas fa-user fa-lg text-light ml-3"></i>manage users
<span class="float-left"><i class="fas fa-angle-down"></i></span>
</a>
<ul class="collapse list-unstyled mt-2 mr-1 pr-2" id="tickets">
<li class="nav-item mb-2">
<a href="create-user.php" class="nav-link text-white customlihamid"><i class="fas fa-user-plus fa-lg text-light ml-3"></i>add user</a>
</li>
<li class="nav-item mb-2">
<a href="#" class="nav-link text-white customlihamid"><i class="fas fa-user-times fa-lg text-light ml-3"></i>delete user</a>
</li>
</ul>
</li>
</ul>
Also, remember to include the following CSS styles:
.customlihamid {
transition: all .4s;
}
.customlihamid:hover {
background-color: #8a8a8a;
border-radius: 5px;
color: #00cc99;
}
.nav-item > .nav-link.active {
background-color: #00cc99;
border-radius: 7px;
box-shadow: 5px 7px 10px #111;
transition: all .3s;
}
.nav-item > .nav-link.active:hover {
background-color: #8eccc1;
border-radius: 7px;
box-shadow: 5px 7px 20px #111;
transform: translateY(-1px);
}
Lastly, don't forget to implement the JavaScript functionality:
$(document).ready(function () {
$('.navbar-nav .nav-link').click(function(){
$('.navbar-nav .nav-link').removeClass('active');
$(this).addClass('active');
})
});
Before adding the JavaScript code, make sure to test your work without it to understand its purpose.