1. Computing

How To Template Your Site

By

When every page of your website follows the same design theme, it is often easiest to create a template for the site. The specific pages of the site only hold their content and not their design. This makes design changes easy, as they take place on all the pages at once, and there is no need to individually update specific pages.
Difficulty: Easy
Time Required: 5 minutes

Here's How:

  1. The first thing you need to do is create a file called header.php. In this file you will hold all of your page design that comes before your content. Here is an example:

    <html>
    <head><title>My Site</title></head>
    <body>
    <h2>My Site Title</h2><p>
    My Site menu goes here........... Choice 1 | Choice 2 | Choice 3
    <hr>
  2. Next we need to make a file called footer.php. This file will contain all of the site design information that goes below the content. Here is an example:

    <hr>
    <small>Copyright 2008 My Site</small><br>
    </body>
    </html>
  3. Finally you need to create the content pages for your site. In this file you will:

    1. Call the header file
    2. Put in the page specific content
    3. Call the footer file

    Here is an example of how:

     
    <?php include 'header.php'; ?>
    <b>Sub-Page Title</b><p>
    Here is the specific content of this page....<br>
    <?php include 'footer.php'; ?>

Tips:

  1. Remember to save all your files with the .php extension.
  2. You can have more than a header and a footer, if needed create other files to include in the middle and call them the same way!
  3. Couple this with the use of a style sheet to change style within the page exclusive content easily as well.
Related Video
Basic PHP Syntax
How to Create a PHP Calendar
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Step By Steps
  5. PHP Include File - web site header - PHP Include

©2014 About.com. All rights reserved.