我已将此 PHP 代码添加到我的导航栏中,以在单击导航栏链接时保持链接处于活动状态。当我通过 www.something.com 导航到该页面时,idex.php 或主页未激活
当访问者到达我的网站时,该 index.php 或主页是 class="active",我该怎么办?
enter code here<?php
function echoActiveClassIfRequestMatches($requestUri)
{
$current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
if ($current_file_name == $requestUri)
echo 'class="active"';
}
?>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand visible-sm" href="#"><img src="assets/images/all.gif" style="padding-bottom:5px;" alt="" height="35em"></a>
<div class="nav-collapse collapse">
<ul class="nav navbar-nav">
<li <?=echoActiveClassIfRequestMatches("index")?>><a href="index.php">Home</a></li>
<li <?=echoActiveClassIfRequestMatches("about")?>><a href="about.php">About us</a></li>
<li <?=echoActiveClassIfRequestMatches("services")?>><a href="services.php">Our services</a></li>
<li <?=echoActiveClassIfRequestMatches("contact")?>><a href="contact.php">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>