|
Home » The tutorial » A little PHP
A little PHP Next step, we're going to split out the header and footer sections into separate files so that we can simply include them were we want them. This will make updates much, much easier. For example, when 2007 rolls around you'll only need to change the copyright date in one place instead of each of your pages.
header.php We take HTML code above the content and move it to a file called header.php. I'm using PHP for this in case we want to come back later and add PHP code. But there's not a requirement that a .php file have any PHP in it, it can be normal HTML.
<html> <head> <title>Bob Smith Photography</title> <link rel="stylesheet" type="text/css" xhref="style.css"> </head> <body>
<div class="main">
<div class="header"> <table width="100%"> <tr> <td align="left"> <img xsrc="logo.gif" width="359px" height="100px" alt="Logo" title="Bob Smith Photography Logo"> </td> <td align="right"> <img xsrc="image.jpg" width="200px" height="100px" alt="Sample Photograph" title="A sample photograph from Bob Smith Photography"> </td> </tr> </table> </div>
<table width="100%"> <tr> <td class="navigation"> <a xhref="/">Home</a><br> <a xhref="/portfolio">Portfolio</a><br> <a xhref="/contact">Contact</a><br> </td> <td class="content">
footer.php And the stuff under the content goes in footer.php.
</td> </tr> </table>
<div class="footer"> © 2006 Bob Smith </div>
</div> </body> </html>
index.php Now we just need to put together an index page. It's going to be called index.php instead of index.html like we had before because we are going to be running PHP code to include the header and footer.
<?php include('header.php'); ?> <h1>Welcome to Bob Smith Photography</h1> Here is Bob's introduction <?php include('footer.php'); ?> Notice how much simpler this page has become. Now when you're ready to make contact.php you only need to change the content and don't need to worry about the header and footer.
See for yourself I've put up the original file and the php version so you can see the difference. There isn't one. You can even view source if you want, you won't find any differences. The difference comes in how much easier it will be for you to do site wide updates down the road. For example, Bob now has 20 pages on his site and he decides to change his logo. He'll only need to change it in header.php and not in each individual page.
|