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
  1. <?php
  2. require("Inc/head.inc.php"); //get header
  3. ?>
  4. your content in this area :)
  5. <?php
  6. require("Inc/foot.inc.php"); //get footer
  7. ?>


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
  1. <?php
  2. session_start();
  3. include("config.php");
  4. ?>


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
  1. <?php
  2. require("Inc/head.inc.php"); //get header
  3. require("nav.php"); //get navigation file
  4. require("Inc/foot.inc.php"); //get footer information
  5. ?>


Thats that then in your nav.php you could have something like...
PHP Code
  1. <?php
  2. $dir = "pages"; //where your pages are
  3. $ext = "php"; //their extennsion
  4. switch($_GET[x]){ //change some links to... ?x=case
  5. default: //default page
  6. require("$dir/home$ext"); //get the main page with news or updates and whatnot
  7. break; //end that page
  8. case 'login': //your login page
  9. require("$dir/login$ext"); //get your login file
  10. break; //end page
  11. } //end switch/get function
  12. ?>


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:
PHP Code
  1. --MAIN
  2. --inc
  3. -header.inc.php
  4. -footer.inc.php
  5. -config.db.inc.php
  6. --images
  7. --pages
  8. --admin
  9. --members
  10. -main.php
  11. -login.php
  12. -index.php
  13. -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
ShadowMage's Avatar
Author:
Views:
2,744
Rating:
Posted on Saturday 10th November 2007 at 12:03 PM
awo
awo's Avatar
okey
Posted on Saturday 10th November 2007 at 02:47 AM
ShadowMage
ShadowMage's Avatar
Nope, thats the nap.php which is used as an include on the index.php
Posted on Friday 9th November 2007 at 11:42 PM
awo
awo's Avatar
Is this code a include????


Code

<?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
?>
Posted on Thursday 8th November 2007 at 09:25 PM
gbt91
gbt91's Avatar
awo actually this is a tutorial site so he doesnt need to upload an example...
you just need to read the tutorial to learn how to do that not to copy it
Posted on Thursday 8th November 2007 at 04:52 PM
awo
awo's Avatar
Can you Upload a exsempel???