突出显示php中的活动菜单链接

时间:2013-04-16 10:20:06

标签: php menu

我在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 -->

2 个答案:

答案 0 :(得分:1)

您将所有内容设置为“我的活动按钮”,并将我的ActiveLink用于厄瓜多尔:

$ecuador='myActiveLink';

试试这个:

$ecuador='myActiveButton';

答案 1 :(得分:0)

改变,

else if($menuLinkid=="gold"){
$gold='myActiveButton';

else if($menuLinkid=="gold-going-green"){
    $gold='myActiveButton';

&安培;变化

$ecuador='myActiveLink';

 $ecuador='myActiveButton';

并重新检查。