Jump to content

PHP Navigation... (sort of?)


forcer

Recommended Posts

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

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>
}

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

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>

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

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.