我在php中做了一个导航,效果很好,几乎完美。我有 6 个页面的站点,活动页面的按钮以不同的颜色突出显示。它在 4 页中有效,但对于“黄金走向绿色”和“关于厄瓜多尔”的链接仍未突出显示。这是我使用的代码:
<?php
//initialize the page variables here so no errors occur in some server environments
$index="myButtons";
$about="myButtons";
$gold="myButtons";
$ecuador="myButtons";
$contact="myButtons";
$documents="myButtons";
//this line gets the file name without the dot and extension
$menuLinkid=basename($_SERVER['PHP_SELF'], ".php");
if($menuLinkid=="index"){
$index='myActiveButton';
} else if($menuLinkid=="about"){
$about='myActiveButton';
} else if($menuLinkid=="gold"){
$gold='myActiveButton';
} else if($menuLinkid=="ecuador"){
$ecuador='myActiveLink';
} else if($menuLinkid=="contact"){
$contact='myActiveButton';
} else if($menuLinkid=="documents"){
$documents='myActiveButton';
}
?>
<div id="header">
<div id="innerheader">
<h1 id="logo"><a href="../index.php"><img src="img/logo.gif" /></a></h1>
<nav id="navigation">
<ul class="menu">
<li><a class="<?php echo $index; ?>" href="../index.php">Home</a></li>
<li>/</li>
<li><a class="<?php echo $about; ?>" href="../about.php">About</a></li>
<li>/</li>
<li><a class="<?php echo $gold; ?>" href="../gold-going-green.php">Gold going green</a> </li>
<li>/</li>
<li><a class="<?php echo $ecuador; ?>" href="../about-ecuador.php">About Ecuador</a></li>
<li>/</li>
<li><a class="<?php echo $contact; ?>" href="../contact.php">Contact</a></li>
<li>/</li>
<li><a class="<?php echo $documents; ?>" href="../documents.php">Documents</a></li>
</ul>
</nav>
</div><!-- /innerheader -->
</div><!-- /header -->