Yashik_san
Yashik_san

Reputation: 1

Highlight active menu link in php

I have made a navigation in php, which works perfect, well, almost perfect. I have 6 pages site and button of active page is highlighted with a different color. In 4 pages it works, but for "gold going green" and "About Ecuador" link remains not highlighted. Here is the code I used:

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

Upvotes: 0

Views: 301

Answers (2)

Vishnu R
Vishnu R

Reputation: 1869

Change,

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

to

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

& Change

$ecuador='myActiveLink';

to

 $ecuador='myActiveButton';

and recheck.

Upvotes: 0

Borniet
Borniet

Reputation: 3546

You set everthing to 'myActiveButton', and use myActiveLink for ecuador:

$ecuador='myActiveLink';

Try this:

$ecuador='myActiveButton';

Upvotes: 1

Related Questions