Abstract:
First we assume that we have a root folder and that all the files we need are in it.
Let's say that we have header.html, footer.html, content1.html, content2.php, main.html, and finally error.html.
Our goal is to use static header (header.html) and footer (footer.html) while the content in between is changing (content1.html, content2.php, main.html).
In the case where no page is selected the main page (main.html) will be displayed by default and if the name does not exist it will display the error page (error.html).
Notice that the content page as we name it can be HTML or PHP.
PHP Code:
The file that is used for the template system is called index.php and contains the following code:
Code :
// hide source code
// hide line numbers
// hide source code
// hide line numbers
1
2 <?php
3
4 /*--TEMPLATE HEADER--*/
5
6 include_once("header.html");
7
8 /*--TEMPLATE CONTENT--*/
9
10 // Default page main.html
11 // If does not exist error.html
12
13 if(!isset($_GET['page'])){
14 include_once('main.html');
15 } else {
16 $pagename = $_GET['page'];
17 switch($pagename)
18 {
19 case content1:
20 $page = "content1.html";
21 break;
22 case content2:
23 $page = "content2.php";
24 break;
25 default:
26 $page = "error.html";
27 }
28 include_once($page);
29 }
30
31
32
33 /*--TEMPLATE FOOTER--*/
34
35 include_once("footer.html");
36
37 ?>
You can add as many page as you want by adding some cases to the switch() function.
Example:
Code :
// hide source code
// hide line numbers
// hide source code
// hide line numbers
1 <?php
2 case whatever:
3 $page = "whatever.php";
4 break;
5 ?>
6
This code can be repeated infinitely as long as the name is unique.
Browsing URL's
Once everything is ready and uploaded to your server web space, you can call any page you want by using:
index.php?page=pagename. In our example above it will be index.php?page=whatever. If you give a page name that does not exist, it will automatically forward you to error.html and if you go directly to the index.php page, it will display main.html by default.
Summary
This system will allow fast site updates. Imagine if you had 40 site pages and just wanted to change the header menu. You would have to change it 40 times! Moreover you won't need to use Iframes anymore that are an old technology.
The template Clean made by Xero is provided as an example. Feel free to download it and to modify it according to your needs. Please respect his work and keep our copyright in the footer.
For support and general question about this tut, please post in our forums only!
Donation:If you like our free quality work, make a donation by using Paypal and tell us what you would like to see improved on our site for the next few months. |
|
File Download
No comments yet













Page Info













