2013-04-16 115 views
0

我在php中做了一个导航,它完美,完美,几乎完美。我有6页网站,活动页面的按钮以不同的颜色突出显示。它有4页有效,但对于“黄金走绿”和“关于厄瓜多尔”的链接仍然没有突出显示。下面是我使用的代码:突出显示在php中的活动菜单链接

<?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 --> 

回答

1

您设置寄托都为 'myActiveButton',并使用myActiveLink厄瓜多尔:

$ecuador='myActiveLink'; 

试试这个:

$ecuador='myActiveButton'; 
+0

谢谢,这正是造成这个问题的原因,我已经做出了改变。 –

+0

很高兴工作!随时upvote和/或选择我的答案,然后;-) – Borniet

0

变化,

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

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

&变化

$ecuador='myActiveLink'; 

$ecuador='myActiveButton'; 

,并重新检查。

+0

非常感谢,Renku,我没有妥善检查这两条线。现在它可以工作。非常感谢您的帮助! –