GAORC.COM Posted August 3, 2009 Share Posted August 3, 2009 Hello all, I am having some problem figuring out where to start. I have a site, that displays a small banner at the top. As the page changes, I want the banner to change with it though. Right now i have the index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Stixx and Stones</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="default.css" /> </head> <body> <div id="upbg"></div> <div id="outer"> <?php include "header.php"; include "menu.php"; ?> <?php $page = $_GET['page']; //Gets the (page=) from the URL if($page){ $site = file_exists($page.'.php') ? $page.'.php' : 'error.php';} else{ $site = 'home.php'; // Else include the default home.php file. } include($site); ?> <?php include "footer.php"; ?> </body> </html> and then the header.php <div id="header"> <div id="headercontent"> <h1>Stixx and Stones</h1> </div> </div> <div id="headerpic"><img src="images/hdrpic.jpg"></div> and menu.php <div id="menu"> <ul> <li><a href="?page=home">Home</a></li> <li><a href="?page=golf">Golf</a></li> <li><a href="?page=archery">Archery</a></li> <li><a href="?page=aboutus">About Us</a></li> </ul> </div> What I would like to have is the hdrpic.jpg be separate pics corespondent to page names, ex. home.jpg, golf.jpg, archery.jpg... Is there a way to make this to where when a link is clicked the header will change corresponding to the page. Quote Link to comment Share on other sites More sharing options...
Adam Posted August 3, 2009 Share Posted August 3, 2009 You'd need to test the value of the page variable and use the correct header. Rather than a complicated series of IF .. ELSE statements though I'd use an array: $header_images = array( 'page_name' => 'corresponding_image.jpg', 'about_us' => 'aboutus.jpg', ); if (array_key_exists($_GET['page'], $header_images)) { $header_img = $header_images[$_GET['page']]; } else { $header_img = 'default_header.jpg'; } Quote Link to comment Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 You can use a SWITCH statement <div id="header"> <div id="headercontent"> <h1>Stixx and Stones</h1> </div> </div> <div id="headerpic"><img src="<?php switch ($_GET['page']) { case 'home': // home header break; case 'golf': // golf header break; case 'archery': // archery header break; case 'aboutus': // aboutus header break; default: // default header } } ?>"></div> Quote Link to comment Share on other sites More sharing options...
GAORC.COM Posted August 3, 2009 Author Share Posted August 3, 2009 Neither of these worked, I thought about doing both, the problem is with my navigation i think. When pages switch, really instead of the whole page changing, only the content section of the page is switched. Index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Stixx and Stones</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="default.css" /> </head> <body> <div id="upbg"></div> <div id="outer"> <?php include "header.php"; include "menu.php"; ?> <?php $page = $_GET['page']; //Gets the (page=) from the URL if($page){ $site = file_exists($page.'.php') ? $page.'.php' : 'error.php';} else{ $site = 'home.php'; // Else include the default home.php file. } include($site); ?> <?php include "footer.php"; ?> </body> </html> In this there is the <?php $page = $_GET['page']; //Gets the (page=) from the URL if($page){ $site = file_exists($page.'.php') ? $page.'.php' : 'error.php';} else{ $site = 'home.php'; // Else include the default home.php file. } include($site); ?> When a link is switched, it changes this section of the page to be ?page=golf, ?page=archery. So because of that, I'm not sure how to get it to read that part and find which header to use. Maybe i need to switch my means of navigation to something different. I'm just trying to keep the site simple. If anyone has suggestions just let me know. Quote Link to comment Share on other sites More sharing options...
Adam Posted August 3, 2009 Share Posted August 3, 2009 Theoretically and syntactically, both examples should work (maybe give or take a parse error). The problem will be in your implementation. How did you have it? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 3, 2009 Share Posted August 3, 2009 Index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Stixx and Stones</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="default.css" /> </head> <body> <div id="upbg"></div> <div id="outer"> <?php $pages = ( 'home' => 'home.php', 'golf' => 'golf.php', 'archery' => 'archery.php', 'aboutus' => 'aboutus.php' ); $img = ( 'home' => 'hdrpic.jpg', 'golf' => 'golf.jpg', 'archery' => 'archery.jpg', 'aboutus' => 'aboutus.jpg' ); $page = isset($_GET['page']) ? $_GET['page'] : ''; if( array_key_exists($page, $pages) ) { $site = $pages[$page]; $hdrImg = $img[$page]; } else { $site = 'home.php'; // Else include the default home.php file. $hdrImg = 'hdrpic.jpg'; } include "header.php"; include "menu.php"; include $site; include "footer.php"; ?> </body> </html> header.php <div id="header"> <div id="headercontent"> <h1>Stixx and Stones</h1> </div> </div> <div id="headerpic"><img src="images/<?php echo $hdrImg; ?>"></div> Should work. Quote Link to comment Share on other sites More sharing options...
GAORC.COM Posted August 3, 2009 Author Share Posted August 3, 2009 Now I'm getting a unexpected T_DOUBLE_ARROW on line 19 of index. That is the 'home' => 'home.php', line? I don't see what is wrong with it? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 3, 2009 Share Posted August 3, 2009 Index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Stixx and Stones</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="default.css" /> </head> <body> <div id="upbg"></div> <div id="outer"> <?php $pages = array( 'home' => 'home.php', 'golf' => 'golf.php', 'archery' => 'archery.php', 'aboutus' => 'aboutus.php' ); $img = array( 'home' => 'hdrpic.jpg', 'golf' => 'golf.jpg', 'archery' => 'archery.jpg', 'aboutus' => 'aboutus.jpg' ); $page = isset($_GET['page']) ? $_GET['page'] : ''; if( array_key_exists($page, $pages) ) { $site = $pages[$page]; $hdrImg = $img[$page]; } else { $site = 'home.php'; // Else include the default home.php file. $hdrImg = 'hdrpic.jpg'; } include "header.php"; include "menu.php"; include $site; include "footer.php"; ?> </body> </html> header.php <div id="header"> <div id="headercontent"> <h1>Stixx and Stones</h1> </div> </div> <div id="headerpic"><img src="images/<?php echo $hdrImg; ?>"></div> Damn, that was a stupid mistake Quote Link to comment Share on other sites More sharing options...
GAORC.COM Posted August 3, 2009 Author Share Posted August 3, 2009 Thanks, works like a charm!!! Quote Link to comment 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.