forcer Posted July 9, 2008 Share Posted July 9, 2008 I am having trouble working out how to do my navigation at the moment they are laid out horizontally HOME - CONTACT - LINKS - ETC... they are all images, and i use a rollover image when hovering over... now what i need to do is have the image replaced, if i am on that page.. for example. all links are black apart from the page i am on (home) which is white... now i click on contact... all links are black apart from contact. basically, the page i am on, has the highlighted navigation link. sorry i am not good at explaining things. the paged are defined by $p if that helps... as my link are displayed as ?p=home thanks. Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/ Share on other sites More sharing options...
john-formby Posted July 9, 2008 Share Posted July 9, 2008 Something like: $page = $_GET['p']; if($page == 'home'){ <a href="index.php?p=home"><img src="home1.gif" alt="home" /></a> } else { <a href="index.php?p=home"><img src="home.gif" alt="home" /></a> } if($page == 'contact'){ <a href="index.php?p=contact"><img src="contact1.gif" alt="home" /></a> } else { <a href="index.php?p=contact"><img src="contact.gif" alt="home" /></a> } if($page == 'links'){ <a href="index.php?p=links"><img src="links1.gif" alt="home" /></a> } else { <a href="index.php?p=links"><img src="links.gif" alt="home" /></a> } Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/#findComment-585194 Share on other sites More sharing options...
MasterACE14 Posted July 9, 2008 Share Posted July 9, 2008 <?php if($_SERVER['PHP_SELF'] == "http://www.mywebsite.com/aboutus.php") { $menu = "Links - Home etc etc"; } ?> thats 1 way of doing it, however quite repetitive and useless. ACE Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/#findComment-585195 Share on other sites More sharing options...
forcer Posted July 9, 2008 Author Share Posted July 9, 2008 Something like: $page = $_GET['p']; if($page == 'home'){ <a href="index.php?p=home"><img src="home1.gif" alt="home" /></a> } else { <a href="index.php?p=home"><img src="home.gif" alt="home" /></a> } if($page == 'contact'){ <a href="index.php?p=contact"><img src="contact1.gif" alt="home" /></a> } else { <a href="index.php?p=contact"><img src="contact.gif" alt="home" /></a> } if($page == 'links'){ <a href="index.php?p=links"><img src="links1.gif" alt="home" /></a> } else { <a href="index.php?p=links"><img src="links.gif" alt="home" /></a> } this is the way i sort of worked out myself... again this seems quite repetative... is there no quicker ways?? also... is there a way to make it highlight home when they first come ot the site, they havent clicked a link so $p isnt defined... therefore it doesnt highlight anything Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/#findComment-585210 Share on other sites More sharing options...
Bendude14 Posted July 9, 2008 Share Posted July 9, 2008 <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); <a href="index.php" <?php if($currentPage == 'index.php') { echo 'class="current"'; } ?>>Home</a ?> You could also use this method to display a different image Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/#findComment-585218 Share on other sites More sharing options...
forcer Posted July 9, 2008 Author Share Posted July 9, 2008 i'm struggling as my current link code is a little larger than that <a href="?p=home" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/nav/nav_home_h.gif',1)"> <img src="images/nav/nav_home_l.gif" alt="home" name="home" id="home" /></a></li> Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/#findComment-585224 Share on other sites More sharing options...
Bendude14 Posted July 10, 2008 Share Posted July 10, 2008 i'm struggling as my current link code is a little larger than that <?php <a href="?p=home" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/nav/nav_home_h.gif',1)"> <img src="images/nav/nav_home_l.gif" alt="home" name="home" id="home" /></a></li> ?> to this <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <a href="?p=home" <?php if($currentPage == 'index.php') { echo 'class="current"'; $pic = 1; } else { $pic = 2; } ?> onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/nav/nav_home_h.gif',1)"> <img src="images/nav/nav_home_<?php echo $pic ?>.gif" alt="home" name="home" id="home" /></a></li> ?> I think something like this will work have not tested it but give it a try and see what you can do Link to comment https://forums.phpfreaks.com/topic/113881-php-navigation-sort-of/#findComment-585956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.