我想把我的菜單放在一個單獨的PHP文件中,所以當我需要編輯它時,我只需要編輯它一次。當我想突出顯示活動頁面時,問題就開始了。有人可以幫我解決它嗎?PHP菜單活動「這裏」鏈接
<?php $currentPage = basename($_SERVER['SCRIPT_FILENAME']); ?>
切換導航
<li><a href="index.php" <?php if ($currentPage == 'index.php') { echo 'id="here"'; }?>><span class="glyphicon glyphicon-home"></span> Home</a></li>
<li><a href="about.php" <?php if ($currentPage == 'about.php') { echo 'id="here"'; }?>><span class="glyphicon glyphicon-picture"></span> About us</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <span class="glyphicon glyphicon-calendar"></span> Services <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="services1.php" <?php if ($currentPage == 'services1.php') { echo 'id="here"'; }?>><span class="glyphicon glyphicon-user"></span> Drivers services</a></li>
<li><a href="services2.php" <?php if ($currentPage == 'services2.php') { echo 'id="here"'; }?>><span class="glyphicon glyphicon-wrench"></span> Shop services</a></li>
</ul>
</li>
<li><a href="application.php"<?php if ($currentPage == 'application.php') { echo 'id="here"'; }?>><span class="glyphicon glyphicon-pencil"></span> On-line Application</a></li>
<li><a href="contact.php" <?php if ($currentPage == 'contact.php') { echo 'id="here"'; }?>><span class="glyphicon glyphicon-envelope"></span> Contact us</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="clearfix"> </div>
</div><!-- navbar -->
修復呢?你沒有告訴我們這個問題 – nogad
如果你把它放在一個單獨的文件中會發生什麼? 'basename($ _ SERVER ['SCRIPT_FILENAME'])'仍應該返回您正在查找的腳本名稱。 – jrn
@nogad當我懸停菜單時,它不會突出顯示活動頁面。 –