Jump to content
xisto Community
Sign in to follow this  
rustypaulin

[php] Prevent Copying A Template For Each New Page

Recommended Posts

This code means every time you make a page you don't need to copy and paste the HTML code for your template, this can make editing links, especially those that appear on every page, and pages a lot easier.

1. Make sure that your template is coded so it is fully expandable.

2. Insert this code into the content area of your template, and save the file as index.php, instead of .html

<?$val = $_GET['id']; // Replace id with whatever you want to use, eg ?id=page
$val .= ".html"; // Makes the filename complete so if you called ?id=index, it would be index.php it has to look for
$dirty = array("..");
$clean = array("");
$val = str_replace($dirty, $clean, $val); // Prevent people from viewing root files like your password

if (isset($_GET['id'])) { // Replace id with whatever you want to use, eg ?id=page
if (file_exists($val)) { // This checks if the file you are trying to call exists
include "$val";
}
else {
include "404.php"; // If the file doesnt exists it calls your 404 error page
}
}
else {
include "home.html"; // If ?id= is not set it will now go to your news page
}
?>


You will also need a file called home.html, that should contain what you want displayed on your home page.

3. Whenever you make a new page you just need to write the content you want included on the page, you won't need the template at all.

So to make a news page you make a file called news.html write the content you want in it, and the link to get to it would be "index.php?id=news"

The main advantage of this script is for when you have links, affiliates, etc displayed on your website that appear on every page and they might need to be changed, so this will make it far faster than having to go through every page to do this.

For your links you would make a new page called links.html and write all your links in it. Then you would put

<? include("links.html") ?>

where ever you want your links to go. Then when you want to edit the links you only need to edit one page instead of numerous other ones.

I hope you find my tutorial useful.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.