esahp Posted October 1, 2006 Share Posted October 1, 2006 I'm not quite sure how to do this or exactly how to explain it. There is a peice of code I want dynamically placed around a certin menu item when that menu item is clicked. The layout is setup where the navigation looks like tabs at the top, and <li id="first" class="active"></li> will make that tab look like its the 'active' one.I have the navigation in nav.php which is included with include();. I'd like for the tab I click on to appear active on that page.Hope I've made this clear enough..[i]nav.php[/i][code]<li id="first" class="active"><a href="index.php">Main</a></li><li><a href="staff.php">Staff/Servers</a></li><li><a href="tos.php">TOS</a></li><li><a href="aup.php">AUP</a></li><li><a href="#">Link</a></li><li><a href="#">Link</a></li>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22673-bit-of-php-help/ Share on other sites More sharing options...
Daniel0 Posted October 1, 2006 Share Posted October 1, 2006 This code should give you an idea of how it's done.[code]<?php$links = array( 'index' => 'Main', 'staff' => 'Staff/Servers', 'tos' => 'TOS', 'aup' => 'AUP', );$current_page = empty($_GET['page']) || !key_exists($_GET['page'],$links) ? 'index' : $_GET['page'];echo <<<EOF<style type="text/css">.active { font-weight: bold;}</style><ul>EOF;foreach($links as $link_key => $link_text){ if($current_page == $link_key) { } $extra = $current_page == $link_key ? " class='active'" : null; echo "\t<li{$extra}><a href='?page={$link_key}'>{$link_text}</a></li>\n";}echo "</ul>\n";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22673-bit-of-php-help/#findComment-101937 Share on other sites More sharing options...
esahp Posted October 2, 2006 Author Share Posted October 2, 2006 Got it working. Quote Link to comment https://forums.phpfreaks.com/topic/22673-bit-of-php-help/#findComment-102049 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.