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: 3,345 |
(Log in to rate) |
User Comments
|
The reason for the two parts of a layout, is because you put your page (could be news, tutorial, graphics etc) between both parts of the layout.
Header|Page|Footer
Imagine that is a layout, you need to include the "Header" before the Page, and the "Footer" after the page.
If you look at any layout, you will see that the page is not the last thing on the page, there usually is coding after it. (Footer) |
|
 Hey
The Top part is the header of the page - in the header, you put all the information that you want to appear BEFORE the content, so maybe a banner...
The bottom part is the footer of the page - in the footer, you put all the info that you want to appear AFTER the content.. Normally people put "Layout and Coding Copyright to _______". In Haileys layout, I'd guess that:
Top: The banner, and the horizontal links
Bottom: The sidebar (which could be it's own sidebar page..), along with the affie links at the bottom.
Does that help? xx
EDIT: Haha... dc277 seems to have beaten me to the punch |
|
| yeah, you basically make a layout and cut it in half so that you can fit anything into the middle. Thanks guys for answering quickly. |
|
Great! I'm trying to get into php right now, so thanks! |
|
Good Luck Anna If you need any help, feel free to send me a shout out 
I just wish this was up when I first started to get into php. I had to read about six different articles before truly understanding what it was all about. |
|
| Yeah, I've been reading articles. I'm just starting though. |
|
I'm sure you'll get the hang of it in no time 
Aside from this guide, Tutorialtastics guide helped me a lot!
http://www.tutorialtastic.co.uk/tutorial/php_includes
|
|
Alright! Thanks, Aashni! |
|
Page: << Previous - 1 2 3
| Post a Comment |
You are not currently logged into your IceCaves account. Log in?
If you would prefer, you can post as a guest below: |