Scott87 Posted August 27, 2008 Share Posted August 27, 2008 Just join up here so I'd like to say HI. I'm currently a PHP beginner so I won't pretend to understand stuff I'm learning and know the basics so far but I'm having a bit of a dilemma: I currently have a banner image, which is static on each page. The pages are generated via a CMS / PHP etc. I want to change the banner image on each page, so e.g. Home - img1, About - img2, Contact - img3 etc. Whats the best way to do this? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 27, 2008 Share Posted August 27, 2008 Well you can use a switch. switch($page){ case 'Home': echo "<img src='img1.jpg' />"; break; case 'About': echo "<img src='img2.jpg' />"; break; default: echo "<img src='img1.jpg' />"; break; } Or you can name your images home.jpg, about.jpg then do this: //Grab the page from the address bar $page = $_GET['page']; if($page == ""){ $page = "home"; } $page = strtolower($page); //Make it lowercase, just incase. echo "<img src='" . $page . ".jpg' />"; Hope that makes sense. Or you could use an if statement, which is basically a switch. Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 27, 2008 Share Posted August 27, 2008 Here's one more idea for you: <?php $banners = array( 'home' => 'image1.jpg', 'about' => 'image2.jpg', 'contact' => 'image3.jpg' ); $page = isset($_GET['page']) ? $_GET['page'] : 'home'; // default to home page echo "<img src=\"{$banners[$page]}\" />"; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted August 27, 2008 Share Posted August 27, 2008 Are you using a single template file that is called for each page? Quote Link to comment Share on other sites More sharing options...
Scott87 Posted August 27, 2008 Author Share Posted August 27, 2008 yes 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.