May 21, 2011
Using PHP to Split Pages


Submitted by Amy Wonnell (from an earlier comment)


Creating Multiple Pages from One Page


There is a really easy way to split your web page into multiple pages to make for easy editing, then lf you want to change anything, you only need to modify one file because that file will appear on every page. This can be used for any number of sections of the page. In the example we are going to split the header, body and footer.

Your files need to end in .php instead of .html

Make the First Page for Your Website



The Header


After you have created the first page for your website, cut and paste everything that will remain the same for the header of your site into another document and call it header.php. This will include the opening html, head tags, css links, and opening body tags.
Include the following code for the title and meta tags:

    <title><?php echo $page_title; ?></title>
    <meta name="description" content="<?php echo $pgDesc ?>"></meta>
    <meta name="keywords" content="<?php echo $keyWords ?>"></meta>

The Footer


Cut and paste everything that will remain the same for the footer of your site into another document and call it footer.php. This will include your closing body and html tags.


Each Page


You will be left with the remaining content that will change for each page of your site.

At the top of each page put the following code:

    <?php
    $page_title = 'Title of page here';
    $pgDesc = 'Page Description here';

    $keyWords = 'Keywords here';

    include ('header.php');
    ?>
At the bottom of each page put the following code

    <?php
    include('footer.php');
    ?>


That's it, it's really handy!

Minor changes were made to the original comments



share / bookmark



Send the link for this page to yourself




join follow up up