Bookmark This Site

Layout and Includes

Author: Derwin Remedios
Submission Date: 2005-08-14
Website: www.daremedy.com
Email: daremedy@daremedy.com
Keywords: php, layouts, includes, programming, simple designs
Synopsis: Make your Website layouts with PHP so you have on layout file so you only need to edit one file to change the layout.

Layout and Includes

Step 1: The first thing to do in order to setup your site with PHP is to take all your pages of content and delete all of the layouts tags. Only leave the parts with the content in it. If the page is not in .html form change the extention from .shtml or whatever you had to .html Remove all if any SSI commands from your .html page, you won't need it anymore. After doing that to all your content pages, take your layout HTML code and put it in Notepad or whatever PHP Text Editor you like to use.

Step 2: If you used SSI commands to include something like left.html make sure to re-add your navigation links and anything else you used SSI for back into your layout HTML code. You don't need SSI commands anymore.

Step 3: Ok, now you should have all your .html content pages without a layout. Your layout HTML code with everything in it(except the content part) should be in notepad or whatever you're using for PHP editing. Insert this code where your content was:

Editing the above tag is explained next, follow directions carefully or the include command will not work. In the "$page.extension" section of the command, you can change the "page" to anything you'd like. Make sure that you change the "extension" part to the extensions of your content pages(which for this tutorial we used .html), but you can change it to other exntension for example if your content pages are .txt files you'd put ".txt" after "$page". So it would look like this "$page.txt". This code tells the browser to load the specified page in your PHP page(Yes, just like SSI include). Now save this as index.php or whatever you'd like the main PHP page to be called.

Step 4: Now to test it, upload the PHP page to your server and 1 page of content that you made in Step 1. Type in the address into your browser, for example http://www.yoursite.com/index.php?id=content This is probably the hardest thing to understand. Here's what each portion of the above link means to clear up any questions:

Let's use http://www.sample.com/index.php?cow=news

index.php or whatever you named it: The main PHP page that has the entire layout in it except the content part

"id" or what you chose in your PHP code: Change "cow" to what you chose in your PHP code inside your PHP page, for example "$cow.html" should be "$id.html" or "$page.html".

"news": The file name of the content page you want to load, in this example the news page is being loaded. Remember don't type in .html extension or anything else, just the file name.

"?": Remember the question mark after your PHP page name in your browser.

Now you should have PHP fully working! Remember to change your links to whatever you chose to name your PHP page and plus the extension to the page. If you don't see anything or get errors, check your code again.

Link to this article:
http://www.daremedy.com/tutorials/php/tut-1124119233.html

[ ^Top ]    [ Go Back ]