Jump to content

[SOLVED] navigation help


imarockstar

Recommended Posts

I have a site with the nav being divs .. and based on if the user is on that page, I want that tab to be a different color.

 

Whats the best way to do this using php ?

 

http://74.55.14.226/~green/solarpower.php

 

you can see that the tab for the solar page is green ... but i need that to change based on what page you are on ...

 

here is my code :

 

<div class='navlinkpush'>

<div class='navlinkactive'><a href='solarpower.php'>solar</a></div>			      
<div class='navlink'><a href='windpower.php'>wind</a></div>			      
<div class='navlink'><a href='nuclearpower.php'>nuclear</a></div>			      
<div class='navlink'><a href='biofuel.php'>bio</a></div>			      
<div class='navlink'><a href='hybridcars.php'>hybrids</a></div>			      
<div class='navlink'><a href='hydrogenpower.php'>hydrogen</a></div>			      
<div class='navlink'><a href='about.php'>about</a></div>			      
<div class='navlink'><a href='blog.php'>blog</a></div>

</div> <!-- #navlinkpush -->	

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/131795-solved-navigation-help/
Share on other sites

this should work...

 

just continue the elseif statements for each link/page you have and complete $arr.

 

should do the job.

 

<?php
$getArr = explode(".", $_SERVER['REQUEST_URI']);
if(strpos($getArr[0], "/solarpower")){
      $link = "solar";
}elseif(strpos($getArr[0], "/windpower")){
      $link = "wind";
}
$arr = array("solar","wind");
foreach($arr as $key => $value){
      echo '<div'.($value==$link ? ' style="navlinkactive"' : ' style="navlink"').'>'.$value.'</div>';
}
?>

create script navbar.php

<?php
$navbar = array(
'solar' => 'solarpower.php',
'wind' => 'windpower.php',
'nuclear' => 'nuclearpower.php',
'bio' => 'biofuel.php',
'hibrids' => 'hybridcars.php',
'hydrogen' => 'hydrogenpower.php',
'about' => 'about.php',
'blog' => 'blog.php'
);
$a = explode('/',$_SERVER['SCRIPT_NAME']);
$activ_link = array_pop($a);
foreach ($navbar as $text => $link){
$class = $activ_link == $link ? 'navlinkactive' : 'navlink';
echo "<div class='$class'><a href='$link'>$text</a></div>\n";
}
?>

and include it in your scripts

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.