
Posted on: 10/09/2009
Php includes could probably be a web designers best friend when creating a static sites. If you have elements on your site that remain the same throughout all the pages, such as a header, menu or footer, then instead of having this on every page you could create one file and include it within all the other pages, making maintaining a site a lot easier.
Instead of having to add the same things into every single page, you create one page with the information in it and then add it to the other pages with the include script.
This means should you ever have to edit this information instead of going through every single page on the site and changing the same bit of thing over and over again, you just edit one page and it will be changed on all of them.
First you need to create your include file, to do this simply add the code you wish to include into other pages then save it. Because you are adding this file into an already existing document you do not need to create a whole new page, all that you need to do is add the elements that you wish to add into your already existing code.
Then on the pages you wish to include the file you have just created add this bit of code :
<?php include("include-file.php"); ?>
Rename include-file.php to what you called your file, for example “header.php or “footer.php”
And there you have it a simple way to maintain your site with the use of php.
One Comment
Thanks for another great article Dizi!
Ill be sure to use this in my next project because it does help a lot when constantly editing sections of a large website.