ttmt Posted December 17, 2011 Share Posted December 17, 2011 Selected navigation on include file. Hi all I can't think how to do this or even if it's possible so I'm hoping someone can help. I have a simple example here to illustrate. http://www.ttmt.org.uk/three.php It's just four linked pages with a heading and a navigation. The navigation has an id="selected" in the <a> tag for that page that changes the color of that link to show you are on that page - very basic. I wanted the put the navigation on the pages with an include file. <?php include("php/includes/nav.php"); ?> and have the code for the nav in nav.php nav.php <ul id="nav"> <li><a href="index.php">Home</a></li> <li><a href="one.php">One</a></li> <li><a href="two.php">Two</a></li> <li><a href="three.php">Three</a></li> </ul> My problem is how can I add the id="selected" to the different links for the different pages if I'm including the navigation code? Hope this makes sense and someone can help. Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/253368-select-navigation-on-include-file/ Share on other sites More sharing options...
JKG Posted December 17, 2011 Share Posted December 17, 2011 you need to know what page you are on. i wouldn't do it this particular way (i would use a tiny function) but as its only 4 pages, put this above the include statement somewhere on the three.php page. <?php $page = 'three'; ?> and in your nav include: <ul id="nav"> <li><a <?php if($page == 'three') echo 'id="selected"';?> href="index.php">Home</a></li> <li><a href="one.php">One</a></li> <li><a href="two.php">Two</a></li> <li><a href="three.php">Three</a></li> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/253368-select-navigation-on-include-file/#findComment-1298839 Share on other sites More sharing options...
son.of.the.morning Posted December 17, 2011 Share Posted December 17, 2011 Could use a bit of JQuery to change the css. <?php if(isset($_GET['id'])) { $id = $_GET['id']; if($id = "home") { echo '<Script type="text/javascript">"$(''#IdorClassName).css('color','#666')</script>'; } //and so on... ?> This can be reused then Quote Link to comment https://forums.phpfreaks.com/topic/253368-select-navigation-on-include-file/#findComment-1298871 Share on other sites More sharing options...
ttmt Posted December 18, 2011 Author Share Posted December 18, 2011 Thanks for the replies I'll go with JKG's suggestion, that works best for me. Quote Link to comment https://forums.phpfreaks.com/topic/253368-select-navigation-on-include-file/#findComment-1298993 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.