Jump to content

[SOLVED] Banner Change With Webpage


GAORC.COM

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/168607-solved-banner-change-with-webpage/
Share on other sites

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

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>

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.

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.

 

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 :o

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.