Jump to content

How Can I Shorten This Up! Please Help


attila2452
 Share

Recommended Posts

How can i shorten this code to make it smaller or more condense.this is my navigation to my website.here is the link to what it looks like and what it does.http://attilahajzer.comli.com/

<?php			if($_GET["page"] == ""){				echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=welcome'><font color='#87CEEB'>  Home  </font></a></li>";}					elseif($_GET["page"] === "welcome"){echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=welcome'><font color='#87CEEB'>  Home  </font></a></li>";}						else{echo"<li><a href='?page=welcome'>  Home  </a></li>";}			if($_GET["page"] === "about"){				echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=about'><font color='#87CEEB'>  About  </font></a></li>";}					else{echo"<li><a href='?page=about'>  About  </a></li>";}			if($_GET["page"] === "media"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";}				elseif($_GET["page"] === "music"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";				}elseif($_GET["page"] === "images"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";				}elseif($_GET["page"] === "images2"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";				}elseif($_GET["page"] === "albums"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";				}elseif($_GET["page"] === "links"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";				}elseif($_GET["page"] === "widgets"){					echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=media'><font color='#87CEEB'>  Media  </font></a></li>";				}else{							echo"<li><a href='?page=media'>  Media  </a></li>";				}			if($_GET["page"] === "downloads"){				echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=downloads'><font color='#87CEEB'>  Downloads  </font></a></li>";			}			else{				echo"<li><a href='?page=downloads'>  Downloads  </a></li>";			}			if($_GET["page"] === "contact"){				echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=contact'><font color='#87CEEB'>  Contact  </font></a></li>";			}else{				echo"<li><a href='?page=contact'>  Contact  </a></li>";			}			if($_GET["page"] === "guestbook"){				echo"<li style='background-image: url(images/nav_hov.jpg);'><a href='?page=guestbook'><font color='#87CEEB'>  Guestbook  </a></li>";			}else{				echo"<li><a href='?page=guestbook'>  Guestbook  </a></li>";			}?>

Edited by Attila2452
Link to comment
Share on other sites

This question was answered in your other Thread? and you said it was working if i remember correctly?
this is different because this is my navigation before that was my title. my navigation has a background. and i just don't want to scew it up. and because i am rellly new with PHP. i rarely know what im reading./ so i have to go over it again and again. and make comments saying what is doing what (from my understanding)you know what i mean?
Link to comment
Share on other sites

Ok, well, i'd make an an array with your links and their corresponding $_GET variable. Then run this array in a foreach() loop, checking with each array element if it equals the $_GET['page'] variable, if it does, then when the link html is created it should have the selected class assigned to it... heres the code, i might not of explained that veeery well, but hopefully you'll see. You can add more links this way by modifying the $links array

<style type="text/css"><!--.selectedList {background-image: url(images/nav_hov.jpg);}.selectedLink {color:#87CEEB;}.unselectedList {}.unselectedLink {}--!></style><?phpfunction buildMenu()	{		$links = array(	array(	'urlVar' => 'welcome',							'title' => 'Home'),									array(	'urlVar' => 'about',							'title' => 'About'),														array(	'urlVar' => 'media',							'title' => 'Media'),														array(	'urlVar' => 'downloads',							'title' => 'Downloads'),													array(	'urlVar' => 'contact',							'title' => 'Contact'),												array(	'urlVar' => 'guestbook',							'title' => 'Guestbook'),											);	$build = '<ul>' . "\n";	foreach($links as $link)		{			if($_GET['page'] == $link['urlVar'])			{			$class = 'selected';			} else {			$class = 'unselected';			}			$build .= '	<li class=' . $class . 'List>		<a href="?page=' . $link['urlVar'] . '" class="' . $class . 'Link">  ' . $link['title'] . '  </a>	</li>' . "\n";			}	$build .= '</ul>' . "\n";		return $build;		}echo buildMenu();?>

Edited by gekk0
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...