Introduction
Most web designs use the same basic layout for every page, and just change the content portion from page to page. This is a great saving of time and effort to build the origional site. The trouble comes when it becomes necessary to change some part of the layout. Using CSS to style all the pages helps, but for some reason it always seems necessary to make changes that affect all pages--and this is a painfull and error prone process.
One solution is to use a PHP template and let the template generate all the common parts of the web page. PHP is a server side programming language, so you need a host that supports PHP development.
This article will run through the steps to create a simple PHP template for use in a small busines or personal web site.
Create Example Web Page
First, the page we will build looks like:
The html markup for this page is in the following block:
"http://www.w3.org/TR/html4/strict.dtd">
<html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Famous Mathematicians - Bernhard Riemann</title>
</head>
<body>
<div>
Famous Mathematicians<br>
Bernhard Riemann
</div>
<div><img src="images/225px-Georg_Friedrich_Bernhard_Riemann.jpeg" alt="">
Bernhard Riemann (1826-1866) was one of the leading mathematicians of
the nineteenth century. In his short career, he introduced ideas of
fundamental importance in complex analysis, real analysis, differential
geometry, number theory, and other subjects. His work in differential
geometry provided the mathematical basis for the general theory of
relativity.<br>
His name is attached to one of the most important outstanding problems,
the Riemann Hypothesis.
</div>
</body>
</html>
Save this block as riemann.php. Now we want to start replacing the static portions of this page with php includes.
At this time, I switch to the notepad++ editor as I will be working entirely in source.
Cut the header portion of the riemann.php and save it as header.php. Then replace the title with a php variable such as $title.
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>$title</title>
</head>
Also cut any other static portions of the page and create then in their own file.
Now replace the top portion of riemann.php with the following:
include("header.php"); ?>
Now upload riemann.php and header.php to your server and you have a template to use for similiar pages.
This example has been kept very simple so it is easy to copy and adapt.