PHP Includes - Making Design Easier

At the top of each of your web pages you have your company name and slogan. What would happen if you needed to update your slogan on every page? It's going to take some time - using PHP Includes will make that process a lot easier and quicker!

Effective Navigation - Increased User Satisfaction

This is the easiest way to build a website, maintain it and still have individual pages for good search engines ranking positions. Using this method only the centre section on each page will be different (the page content). The top, side and bottom pages are all 'included' automatically by PHP.


For instance, if you have a website of about 20 pages and need to change the menu system or add a few more links, then by making use of PHP includes you can change just the one file (the included one) and all others pages which utilise this included file will also be automatically updated.

Step One

A good rule is to keep all files which are related to a particular website in the same folder. Create a new HTML page, save this page as template.php and save it in your website folder. The extension of the page you create has to end with .php and not .html. All page extensions need to end with .php to allow PHP to parse the pages.

Step Two

We now need the pages to include. So open up a new blank page in your editor and then save this blank page and call it header.php


Repeat this process for footer.php and menu.php. So now you should have 3 blank pages and the template.php page. You now have all the pages created that will form the basis of your website.

Step Three

Open up the header.php page and add some text or logo. For our template just add some text which says: "Welcome to PHP Include Test".


Next open up the footer.php page and add a copyright notice. The footer can be used for other purposes including more links, but all this can be added later.


Then open up the menu.php page and add the following:


Home
About Us
Contact Us


Now it is time to open up the template.php page - this appears blank and will remain so. We are just going to use this page as a template page to create our other pages. So with this page open in your HTML editor, save this page as index.php.


Add some text to your index, perhaps an image or two and save it in your website folder. In the places where you would expect to see the header, menu and footer you need to add the following text (exactly as shown):

 

<?PHP include "header.php"; ?>

<?PHP include "menu.php"; ?>

<?PHP include "footer.php"; ?>

Step Four

To view  the pages you have created you will need to upload them to a PHP enabled web server. Nearly all hosts support this now as standard. Point your browser to the uploaded index page and you should be able to see the basic layout and pages we have just created.

Step Five

Once you have proved to yourself that the index.php does display with the detail from the header.php, menu.php & footer.php files, you can start creating extra pages. You do this by opening the template.php page in your HTML editor and saving it with the name of your new page - remember the new page must end .php.


Add text etc to the new page(s) and of course the "include statements" detailed in Step Three.


Do not forget to add the name and link details of the new pages to your menu in the menu.php file (or amend the existing menu details), to upload all the new pages and revised "include" files to your server.


Thats it! Now you can play around adding text and images to get the full idea of what PHP Includes can do. Have fun!

Webcritique.org is a Priday Design Studio service.
Priday Design Studio is based in Birmingham, UK and provides web design and site maintenance services for SME & club/associations throughout the UK. Domain names and hosting facilities are provided by associated site, PDS-Hosting Solutions, enabling us to provide you with a complete service.