- Impact
- 1
I come up with this after getting really tired of updating multiple files when ever I wanted to make a site wide layout change. It does require use of PHP, which means your pages have to be .php instead of .htm, .html
Its is a bit of code that allows you to create one layout file and load all of your content into that layout.
To use this simply design your layout and place this where you want you content to load. Create your content files.
Now your links will look like this:
Instead of having to search through all the lines of code to update content you can keep the content and layout seperate. Just a note with how I posted the code a file called 'main' will load when the page is opened for the first time. You can chage this by editing the line $page = "main"; to reflect the filename you would like to load when first accessed.
Its is a bit of code that allows you to create one layout file and load all of your content into that layout.
Code:
<?php
$config["path"] = "LOCATION OF YOUR CONTENT TO LOAD";
$config["ext"] = EXTENSION OF THE CONTENT FILES EX. .php, .htm, .txt";
if (!isset($_REQUEST["page"])){
$page = "main";
} else {
$page = $_REQUEST["page"];
$page = urldecode($page);
$page = trim($page);
$page = strip_tags($page);
if (substr_count($page,"..") > 0 || substr_count($page,"~") > 0){
$page = "main";
}
}
$full = $config["path"] . $page . $config["ext"];
if (!is_file($full) || is_dir($full) || !file_exists($full)){
die ("Sorry, the page you are looking for is gone. Please email the webmaster with the URL currently in your address bar so that it can be corrected. Thanks!");
} else {
require_once($full);
}
?>
To use this simply design your layout and place this where you want you content to load. Create your content files.
Now your links will look like this:
Code:
<a href="index.php?page=filename>Content</a>
Instead of having to search through all the lines of code to update content you can keep the content and layout seperate. Just a note with how I posted the code a file called 'main' will load when the page is opened for the first time. You can chage this by editing the line $page = "main"; to reflect the filename you would like to load when first accessed.