Earlier I posted a tutorial on making PHP Template (which I didn't made, but perfected it).
I had posted a link to my free site where I had written it in detail. But due to some reasons I had 2 remove it. As I have made the script even better I M giving a small tutorial here.
For starters, in a PHP tutorial a single file is used as template in which content from other files is pulled in. So when you want 2 edit a menu item which is present in all D pages U have 2 just edit the template file and upload it. Also you don't have to add any HTML codes inside the content files other than those which will be inside D <body> </body> tags.
First create your Template file and name it as index.php. Put all the links and other things that U want in it then in the area where U want 2 put the content after menus and before footer paste this code.
<?php
$common = 'page1'; // Home Page
$page = isset($_GET['p']) ? $_GET['p'] : $common;
$page = basename($page);
$default = 'main'; // Home Folder (you must place all the content files in a folder)
$directory = isset($_GET['dir']) ? $_GET['dir'] : $default;
$directory = basename($directory);
if (!file_exists($directory.'/'.$page.'.php')) {
$page = '404';
$directory = 'main';
}
include($directory.'/'.$page.'.php');
?>
Save it and U are done.
For the links U have 2 make some changes. As D script checks for folder & file U have 2 write links like this.
Instead of <a href="folder/page.php">Link</a>
Write <a href="?dir=folder&p=page">Link</a>
No comments:
Post a Comment