Integrate PHP into your Website LayoutWritten by: Haily | This tutorial will teach you how to use PHP includes to establish uniformity and efficiency in your layout.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.
| Written by: Haily | Added: Apr 11 2009 | Last Modified: Feb 6 2010 | Views: 2,355 | (Log in to rate) | Member Comments
|
The real trick is not not getting errors but understanding what the errors mean. XP
I hope you got that. xD |
|
| I didn't cause you said not twice. |
|
| What if I said "isn't not" instead of "is not not"? |
|
 Haily said: What if I said "isn't not" instead of "is not not"?
:o So you meant to say 'not' twice? |
|
 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 |
|
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 |
|
| Ahaha. I just learned his a few days ago. x) |
|
| Isn't it grasshopper, not cricket? |
|
Padawan.
Edit: And Haily is master Yoda. |
|
 Puffs said: Isn't it grasshopper, not cricket?
Nah. Haily likes to be, somewhat, original :O |
|
| =O Maybe Megan Fox will notice! |
|
| 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. |
|
| True...but Haily wishes she was. Then she'd be - you know - more portable. And cheaper to go the movies :O |
|
| Yes, I see where you are going with this. Say, Haily are you attracted to insects? |
|
| o_o ... I step on insects. |
|
| Murderer! How could you say that about Megan? D= She'll dump you if you don't show her enough respect, you know. |
|
| 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? |
|
| I so hope that Megan Fox sees this! xD That would be AWESOME! |
|
| She says she doesnt go on the internet much ;O |
|
| Arrgh, darn!! |
|
Haha, imagine if she DID see it
Haily, how much do you wish you could meet her, one on one, in person? |
|
... uh, personally I couldn't care less if I did or not. o.o
|
|
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 :/ |
|
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
| Post a Comment |
In order to post a comment, you must be logged into the IceCaves.net Community. Click here to login. |

|
Your Account |