Split Layout
Say you have a layout that has tons of HTML and all that and you do not want to waste space of putting all html in every file you have to deal with.
First off, make new folder and call it
Inc
Next make two files one named
head.inc.php and another called
foot.inc.php
You do not want just .inc files or people(Rippers) can steal your layout and possibly file lawsuit.
In your head file you will want to post ALL the HTML until the point of the actual content such as news and all that.
In the footer file you will post the remaining bits of HTML at the top ending the main content area.
Next in all the files you have that need the HTMl and all that you could do:
PHP Code
<?php
require("Inc/head.inc.php"); //get header
?>
your content in this area :)
<?php
require("Inc/foot.inc.php"); //get footer
?>
This will grab all your HTML and you do not have to put it on all the pages you have.
And just a tip here... if you put
PHP Code
<?php
session_start();
include("config.php");
?>
At the top you will only have to do that 1 time instead of all the files that need to get configuration files and information.
And if you use
This tutorial it will go for the whole website instead of just the pages you want.
Or if you want to do something more advanced you could use a switch get function in a file called nav.php then in a separate folder named
pages you could have all your files then your
index.php
Could have something like...
PHP Code
<?php
require("Inc/head.inc.php"); //get header
require("nav.php"); //get navigation file
require("Inc/foot.inc.php"); //get footer information
?>
Thats that then in your nav.php you could have something like...
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$dir = "pages"; //where your pages are
$ext = "php"; //their extennsion
switch($_GET[x]){ //change some links to... ?x=case
default: //default page
require("$dir/home$ext"); //get the main page with news or updates and whatnot
break; //end that page
case 'login': //your login page
require("$dir/login$ext"); //get your login file
break; //end page
} //end switch/get function
?>
Then that would most likely leave a nice organized directory.
this here is a simple listing of how i have setup one or two of my sites:
Code
--MAIN
--inc
-header.inc.php
-footer.inc.php
-config.db.inc.php
--images
--pages
--admin
--members
-main.php
-login.php
-index.php
-nav.php
Keeps all the pages separate and organized so you can find things easier.
Hopefully this tutorial/guide has helped you split your layout into header files and footer files and taught you something :P