Includes are one of the simplest yet most useful items available to a web site designer. Not only will they speed up the load times of web site but they also keep a web site easy to maintain. Includes are used on items of web sites that remain the same on each page, this might include menus, headers and footers. By using an include for one of these items means that only one change is needed to change every page of a web site, saving huge amounts of time.
What you will need:
1. The first step is choose an area of a page that we want to make an include, below is a very simple web page example.
<html>
<head>
<title>This is a sample web page</title>
</head>
<body>
<ul>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
<li>Menu Item 4</li>
</ul>
<p>This is a very simple web page that we are using as an example for this tutorial.</p>
</body>
</html>
In this simple example we will make the menu an include, this will allow us to make changes to this menu across all pages by just editing the include file.
2. We will next create a new folder called 'include' (this isn't necessary but it helps keeps files in order) and create a new php inside called 'links.inc.php' (this file can be called anything you like). Inside this new links.inc.php file we will add the menu code from the example above.
<ul>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
<li>Menu Item 4</li>
</ul>
3. Now we will remove the menu from the original example and call the new links.inc.php so that it is included in the page. The finished example will now look like the following:
<html>
<head>
<title>This is a sample web page</title>
</head>
<body>
<?php require_once('include/links.inc.php'); ?>
<p>This is a very simple web page that we are using as an example for this tutorial.</p>
</body>
</html>
We use a require_once apposed to a straight forward include so that a fatal error is thrown up if the include file cannot be found.
4. All you then need to do is replace the location and name of the file if you have changed them from those given in this tutorial.
Display a Random Image with PHP
Self Validating Form with PHP
Using PHP Includes to your Advantage
Clean up your Website URLs with htaccess
Create a tag cloud for your site
Create an HDR Image from a Single Photo
Sharpen your Photos for Professional Results
Isolate a Colour in a Photo for a Striking Result
Digitally Colour a Black and White Photo
Using Adjustment layers in Photoshop
Using Blending Modes in Photoshop
Getting Pantone Values for use in Print