Mar 17,  PST

Integrate PHP into your Website Layout
Written by: Haily | This tutorial will teach you how to use PHP includes to establish uniformity and efficiency in your layout.
  Mxx Digg StumbleUpon  

With PHP includes, you can place your website layout into a file or two and load the layout's files in each page. With this, you can have multiple pages on your site that access a single set of files that make up your layout, allowing you to have to edit only these files when you edit or modify your website's layout. An alternative to using PHP is building your layout on the index page of your site and accessing each page via an iframe. The advantage of a PHP layout is linking to pages of your site from emails and search engines like Google.
The Gist of It
The concept is simple. Divide your layout into two pieces: (1) everything before the page content, and (2) everything after the page content. If you're still not sure on how two do this, keep reading. Otherwise, this is the gist of it.

<?php
include("url_to/top.php");
?>

PAGE CONTENT GOES HERE

<?php
include("url_to/bottom.php");
?>

Note: Remember that pages which execute PHP scripts must have the .php extension.
Dividing Your Layout
Okay, the first thing you must do is place your website layout in one page where you can easily see all of the code that makes up your site. Here's my example of a website layout:

<HTML>
<HEAD>
<TITLE>IceCaves.net - Your Webmaster Resources</TITLE>
<META name="description" content="IC offers free website scripts and articles for webmasters.">
<META name="keywords" content="webmaster,script,php,javascript,css,html,article,tutorial">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<div align="center">
<h1>IceCaves.net</h1>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="left">link<br>link<br>link<br>link<br>link</td>
<td align="center">PAGE CONTENT GOES HERE</td>
<tr>
</table>
<i>Copyright 2009 IceCaves.net. All right reserved.</i>
</BODY>
</HTML>

Now, to divide the layout into your top.php and bottom.php, start by cutting and pasting everything before the PAGE CONTENT GOES HERE text into a new file named top.php. Then, cut and paste everything after the PAGE CONTENT GOES HERE text into another new file named bottom.php. Save and upload these two new files to your site. With my example, my top and bottom layout files will look like this:
top.php

<HTML>
<HEAD>
<TITLE>IceCaves.net - Your Webmaster Resource</TITLE>
<META name="description" content="IC offers free website scripts and articles for webmasters.">
<META name="keywords" content="webmaster,script,php,javascript,css,html,article,tutorial">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<div align="center">
<h1>IceCaves.net</h1>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="left">link<br>link<br>link<br>link<br>link</td>
<td align="center">

bottom.php

</td>
<tr>
</table>
<i>Copyright 2009 IceCaves.net. All right reserved.</i>
</BODY>
</HTML>

Now that you have the two layout files created, use PHP to include these two files into each of your pages using the same concept as before. Just remember to change the url_to inside the include function to the proper url of where your two layout files have been uploaded to.

<?php
include("url_to/top.php");
?>

PAGE CONTENT GOES HERE

<?php
include("url_to/bottom.php");
?>

Also, don't forget that now each of your pages are executing a PHP code. Therefore, the extensions of these pages must be .php.

  Mxx Digg StumbleUpon  

| Written by: Haily | Added: Apr 11 2009 | Last Modified: Feb 6 2010 | Views: 2,355 | (Log in to rate) |

Member Comments

Page: << Previous - 1 2  
Haily of icecaves.netSeptember 21 2009, 9:38 pm PST - Karma: 0 - Quote - Link -
The real trick is not not getting errors but understanding what the errors mean. XP

I hope you got that. xD
Thomas of icecaves.netSeptember 21 2009, 9:40 pm PST - Karma: 0 - Quote - Link -
I didn't cause you said not twice.
Haily of icecaves.netSeptember 21 2009, 9:50 pm PST - Karma: 0 - Quote - Link -
What if I said "isn't not" instead of "is not not"?
Thomas of icecaves.netSeptember 21 2009, 9:54 pm PST - Karma: 0 - Quote - Link -
Haily said:
What if I said "isn't not" instead of "is not not"?

:o So you meant to say 'not' twice?
Sabriel of serenium.fale...September 21 2009, 9:57 pm PST - Karma: 0 - Quote - Link -
Haily said:
What if I said "isn't not" instead of "is not not"?

Makes sense to me xD
That 'isn't not' just wouldn't make sense and if you had used that Kyra would have been on you within seconds xD
kyraSeptember 22 2009, 6:33 am PST - Karma: 0 - Quote - Link -
I would have said:

'The real trick is, even if you get errors, you know what they mean.'
Even - 'Errors are fine, as long as you know what they mean'
Or the Haily-way: 'Errors are fine, young cricket. As long as you understand their true meaning...*bows*'

Or something along those lines ;D
Stephanie of mykismet.ne...September 22 2009, 5:09 pm PST - Karma: 0 - Quote - Link -
Ahaha. I just learned his a few days ago. x)
Puffs of ipawd.netSeptember 22 2009, 5:15 pm PST - Karma: 0 - Quote - Link -
Isn't it grasshopper, not cricket?
James of icecaves.netSeptember 22 2009, 5:21 pm PST - Karma: 0 - Quote - Link -
Padawan.

Edit: And Haily is master Yoda.
kyraSeptember 22 2009, 5:56 pm PST - Karma: 0 - Quote - Link -
Puffs said:
Isn't it grasshopper, not cricket?

Nah. Haily likes to be, somewhat, original :O
Icy of finalriot.comSeptember 23 2009, 4:40 am PST - Karma: 0 - Quote - Link -
=O Maybe Megan Fox will notice!
Jenny of windymill.skyne...September 23 2009, 2:09 pm PST - Karma: 0 - Quote - Link -
I think 'cricket' sounds better, anyway. To be honest, I don't think Megan Fox will notice as she is neither a grasshopper nor a cricket.
kyraSeptember 23 2009, 2:33 pm PST - Karma: 0 - Quote - Link -
True...but Haily wishes she was. Then she'd be - you know - more portable. And cheaper to go the movies :O
Jenny of windymill.skyne...September 23 2009, 2:36 pm PST - Karma: 0 - Quote - Link -
Yes, I see where you are going with this. Say, Haily are you attracted to insects?
Haily of icecaves.netSeptember 23 2009, 2:38 pm PST - Karma: 0 - Quote - Link -
o_o ... I step on insects.
kyraSeptember 23 2009, 2:39 pm PST - Karma: 0 - Quote - Link -
Murderer! How could you say that about Megan? D= She'll dump you if you don't show her enough respect, you know.
Jenny of windymill.skyne...September 23 2009, 2:41 pm PST - Karma: 0 - Quote - Link -
Well, don't!! Show the Megan and her background some respect or she'll get the 'in-laws' in on you. Can I come to the wedding?
James of icecaves.netSeptember 23 2009, 4:04 pm PST - Karma: 0 - Quote - Link -
I so hope that Megan Fox sees this! xD That would be AWESOME!
Icy of finalriot.comSeptember 23 2009, 4:41 pm PST - Karma: 0 - Quote - Link -
She says she doesnt go on the internet much ;O
James of icecaves.netSeptember 23 2009, 4:49 pm PST - Karma: 0 - Quote - Link -
Arrgh, darn!!
ZaphiieSeptember 27 2009, 3:14 am PST - Karma: 0 - Quote - Link -
Haha, imagine if she DID see it
Haily, how much do you wish you could meet her, one on one, in person?   
Haily of icecaves.netSeptember 27 2009, 10:28 pm PST - Karma: 0 - Quote - Link -
... uh, personally I couldn't care less if I did or not. o.o
kyraSeptember 28 2009, 8:15 am PST - Karma: 0 - Quote - Link -
Dear boy - no need masking your face so!
Did your heart love 'till now? Foreswear it, sight!
For you ne'er saw true love till this night.

And, yes, I /am/ reading Romeo and Juliet in school :/
Jenny of windymill.skyne...September 28 2009, 10:34 am PST - Karma: 0 - Quote - Link -
HAHA! And who said I was stupid???? I actually knew that. We're reading Hamlet by the way. I liked the movie with Leonardo, I liked watching it in English. Leo's way fitter than the other versions of the play we've seen.

And also, admit it, Haily. Let's not be coy about it because coyness is a feminine characteristic.

Page: << Previous - 1 2  

In order to post a comment, you must be logged into the IceCaves.net Community.
Click here to login.


Username:

Password:


Figmint WindymillHeartdrops
The IceCaves.net Topsites


Windymill | Neoeditor | Rabidish | KeliJo.net | NeopetsGuide | Hidden Star | The Neopian Bay | Skylish | Tugboat | Dash of Color | Neo Nutters | Smiley Helper | Spicy-Sugar | Vintaged.org | MSPT | Darkgirl's Life | Gamexe.net