imarockstar Posted November 7, 2008 Share Posted November 7, 2008 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 --> Quote Link to comment https://forums.phpfreaks.com/topic/131795-solved-navigation-help/ Share on other sites More sharing options...
MatthewJ Posted November 7, 2008 Share Posted November 7, 2008 Maybe I am misunderstanding, but couldn't you just use css? Create a class called something like "curr" and on each of those pages, use the other class... If it is a different color for EACH page, then create a class for each tab color. Quote Link to comment https://forums.phpfreaks.com/topic/131795-solved-navigation-help/#findComment-684643 Share on other sites More sharing options...
imarockstar Posted November 7, 2008 Author Share Posted November 7, 2008 that would be the easiest way .. however, since my navigation is in an includes its the same file for all of my pages .. Quote Link to comment https://forums.phpfreaks.com/topic/131795-solved-navigation-help/#findComment-684649 Share on other sites More sharing options...
mrMarcus Posted November 7, 2008 Share Posted November 7, 2008 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131795-solved-navigation-help/#findComment-684698 Share on other sites More sharing options...
sasa Posted November 7, 2008 Share Posted November 7, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131795-solved-navigation-help/#findComment-684707 Share on other sites More sharing options...
imarockstar Posted November 7, 2008 Author Share Posted November 7, 2008 awesome works great !!!! b Quote Link to comment https://forums.phpfreaks.com/topic/131795-solved-navigation-help/#findComment-684714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.