Honesty Rocks! truth rules.

Question About Php Includes How would you include a frame AROUND the page?

HOME      >>       Programming

tricky77puzzle

I'm trying to make a layout for my website for the areas that aren't occupied by Wordpress, and I want to use PHP includes to do it.

So far, I know how to use <?php include ... ?> tags, like this:

<table><?php include "sidebar.php" ?></table>

This is okay, but I want to be able to include everything in one "container" file. Kind of like this:

For every HTML file that I include:
<html><head><?php include "frame.php" ?><title></title></head><body><!-- Include pure page content here --></body></html>

This is so that the HTML files I originally made stay HTML files except for the PHP sidebar I add, and I won't need any permalinks.

How would I go about doing this?

jlhaslip

In order to have your 'html' pages parsed as PHP, you will need to create an .htaccess file and change the list of file extensions which should be parsed as php.
This is done by adding the htm and html file extensions to the php application handler.

There have been several Tutorials about how to do this. Here is one of them that is quite well explained.

http://forums.xisto.com/topic/46392-do-you-want-to-use-php-code-in-your-html-pages-within-two-minutes-you-will/


tricky77puzzle

In order to have your 'html' pages parsed as PHP, you will need to create an .htaccess file and change the list of file extensions which should be parsed as php.This is done by adding the htm and html file extensions to the php application handler.

There have been several Tutorials about how to do this. Here is one of them that is quite well explained.

http://forums.xisto.com/topic/46392-do-you-want-to-use-php-code-in-your-html-pages-within-two-minutes-you-will/


Sorry, I misphrased myself. I meant, I want my HTML files to stay the way they were, except for being renamed to PHP and having the sidebar added in as a "header".

I don't really feel like editing the .htaccess file.

jlhaslip

If you want a 'common' snippet of php code added into all of your site pages, the system needs to know that the php is in there and that it needs to send the file to the php parser.Two ways to do that:1. rename the files with a php extension. ( you don't want to do that)2. Add the above to your htaccess file. (you will need to do this)Without the file extension, or the application/type redirect in your .Htaccess file, the php code will be treated as text and display on your page as raw code, possibly displaying stuff you don't want public, like Database Information.You need to do one or the other.


tricky77puzzle

If you want a 'common' snippet of php code added into all of your site pages, the system needs to know that the php is in there and that it needs to send the file to the php parser.
Two ways to do that:

1. rename the files with a php extension. ( you don't want to do that)
2. Add the above to your htaccess file. (you will need to do this)

Without the file extension, or the application/type redirect in your .Htaccess file, the php code will be treated as text and display on your page as raw code, possibly displaying stuff you don't want public, like Database Information.

You need to do one or the other.


Well, actually I do want to rename the files. I just want to know how I can build the site AROUND the pure code that exists as my HTML page. I just don't want to have to put the "table" stuff in every page, and would rather have all the table containers and stuff in one php file that I can put a <?php include "frame.php" ?> for in the page. That's my only problem.

truefusion

Are you basically saying you want a "header", a "footer" and a "content" file to be included all in one page as to act as a template to use as your main structure for your site? I'm having a bit of trouble understanding you, too.


[John]

The easiest way would be to have the content already inside the frame you are trying to include. if it is called content.php....on the content.php page you can simply echo an iframe, and in the iframe use <?php include("page1.html") ?> or something of the sort. that way, once loaded, the content is already in the middle iframe. You can simple target iframes to change the content in the middle through links :P


BuffaloHelp

You can also perform PRINT or ECHO to spit out HTML codes, such that:

<?phpprint '<html><head>';include "frame.php";print '<title></title></head><body><!-- Include pure page content here --></body></html>';?>

You don't have to do any modification to your code and simply save this page as filen_name.phpNotice the usage of single quote verses double quote.


tricky77puzzle

Are you basically saying you want a "header", a "footer" and a "content" file to be included all in one page as to act as a template to use as your main structure for your site? I'm having a bit of trouble understanding you, too.

Well, sort of. I want to be able to include the frame in one file, and reference it as a "header" file in the page content.

To [John], I don't want to use iframes, because that would defeat the purpose of using PHP for it.

I want to be able to include a top bar and a sidebar inside the include frame. Currently, the page layout I want looks like this:

<html><!-- include HTML header code here --><body><table id="page" width="100%"> <tr><td> <table id="top-bar" height="148px"> <tr><td width="172px"><img src="logo.png"></td><td><!-- title --></td></tr> </table> </td></tr> <tr><td> <table id="sidebar" width="256px"> <!-- does the "width" and "height" option go into CSS? I don't remember. --> <tr style="background-image: sidebar-top.png;"><!-- link to home page --></tr> <tr style="background-image: sidebar-middle.png; background-repeat: repeat;"><!-- other links --></tr> <tr style="background-image: sidebar-bottom.png;"><!-- spotlight link: possibly to Xisto, maybe an ad or two --></tr> </table> </td><td> <!-- insert pure page content here --> </td></tr></table></body></html>

As you can see, it's quite a simple page layout. Now what I want to do is to cut out everything except for the pure page content and the includes that I want to add. How would I go about doing that?

KansukeKojima

I believe I understand what you are saying... If I understand correctly: you want to have a basic template seperated from the the rest of your content, and then just parse the content into the template, or the template around the content right? If this is the case I would recommend using this.


<?php//----------------------------------// Content Include//----------------------------------$cont = $_GET['cont'];$default = "HOME PAGE FILE HERE"; if($cont == "") { $cont = $default; } elseif(isset($cont)) { $cont = $cont; } if(file_exists("$cont.html")) { $content = file_get_contents("$cont.html");} else { $content = "Unfortunately, the file you were looking for could not be located.";}//----------------------------------// Content Select//----------------------------------if(isset($cont)) {$content_select = <<< html$contenthtml;} else {$content_select = <<< htmlThere is a content_select error.html;}//---------------------------------//Template//---------------------------------$template = <<< html<html><!-- include HTML header code here --><body><table id="page" width="100%"> <tr><td> <table id="top-bar" height="148px"> <tr><td width="172px"><img src="logo.png"></td><td><!-- title --></td></tr> </table> </td></tr> <tr><td> <table id="sidebar" width="256px"> <!-- does the "width" and "height" option go into CSS? I don't remember. --> <tr style="background-image: sidebar-top.png;"><!-- link to home page --></tr> <tr style="background-image: sidebar-middle.png; background-repeat: repeat;"><!-- other links --></tr> <tr style="background-image: sidebar-bottom.png;"><!-- spotlight link: possibly to Xisto, maybe an ad or two --></tr> </table> </td><td><!-- THIS IS WHERE YOUR CONTENT WOULD BE PARSED INTO THE PAGE--!> $content_select<!-- THIS IS WHERE YOUR CONTENT WOULD BE PARSED INTO THE PAGE--!> </td></tr></table></body></html>html;//----------------------------------// Display the Final Template//----------------------------------echo $template;?>

After you create the above index.php file, create all your content on seperate .html files. For your links, simply use "<a href="index.php?cont=page">" Without the .html extension, as it will be placed in after the file name.

jlhaslip

Here is a link to a Tutorial or 2 over at the Xisto site which you might find helpful.

http://forums.xisto.com/topic/89461-cms102-content-management-system-design-basic-cms-with-php-flat-file-databases/


tricky77puzzle

I believe I understand what you are saying... If I understand correctly: you want to have a basic template seperated from the the rest of your content, and then just parse the content into the template, or the template around the content right? If this is the case I would recommend using this.
(code)

After you create the above index.php file, create all your content on seperate .html files. For your links, simply use "<a href="index.php?cont=page">" Without the .html extension, as it will be placed in after the file name.


That's exactly what I don't want to do. I don't want the page file to be an argument on index.php; I just want it to be a file by itself. Is that possible?

KansukeKojima

So you want all of your websites content to be in a single file?


tricky77puzzle

So you want all of your websites content to be in a single file?

No, that's not what I meant. I mean that I want the container to be 1 page, and then all the other files will link to it with the PHP include.

Sorry if I'm messing myself up.

KansukeKojima

Ok what you could do:

Create a php file that contains the layout of your page. make it look somewhat like this (call it layout.php)

<?php//---------------------------------//Layout top section//---------------------------------$top = <<< html<!-- include HTML header code here --><body><table id="page" width="100%"> <tr><td> <table id="top-bar" height="148px"> <tr><td width="172px"><img src="logo.png"></td><td><!-- title --></td></tr> </table> </td></tr> <tr><td> <table id="sidebar" width="256px"> <!-- does the "width" and "height" option go into CSS? I don't remember. --> <tr style="background-image: sidebar-top.png;"><!-- link to home page --></tr> <tr style="background-image: sidebar-middle.png; background-repeat: repeat;"><!-- other links --></tr> <tr style="background-image: sidebar-bottom.png;"><!-- spotlight link: possibly to Xisto, maybe an ad or two --></tr> </table> </td><td>html;//---------------------------------//Layout bottom section//---------------------------------$bottom = <<< html</td></tr></table></body>html;?>

Ok, so in this you have two variables. The first being the 'top' part of your layout. This would be everything before your 'pure content' areas. The second variable is the 'bottom' part of your layout. This would be everything after your 'purecontent' area. So in short it would look like this.

$top
content
$bottom

Now here is where what you want comes into play. You can echo your entire layout around your content like this.

<html><?php include ("layout.php");echo $top;?>Put your content here!!!<?phpecho $bottom;?></html>

I think this should work... maybe jlhaslip or another member more expierienced than me could point out any flaws if any... and I hope this is what you were looking for....

tricky77puzzle

Ok what you could do:
Create a php file that contains the layout of your page. make it look somewhat like this (call it layout.php)

<?php//---------------------------------//Layout top section//---------------------------------$top = <<< html<!-- include HTML header code here --><body><table id="page" width="100%"> <tr><td> <table id="top-bar" height="148px"> <tr><td width="172px"><img src="logo.png"></td><td><!-- title --></td></tr> </table> </td></tr> <tr><td> <table id="sidebar" width="256px"> <!-- does the "width" and "height" option go into CSS? I don't remember. --> <tr style="background-image: sidebar-top.png;"><!-- link to home page --></tr> <tr style="background-image: sidebar-middle.png; background-repeat: repeat;"><!-- other links --></tr> <tr style="background-image: sidebar-bottom.png;"><!-- spotlight link: possibly to Xisto, maybe an ad or two --></tr> </table> </td><td>html;//---------------------------------//Layout bottom section//---------------------------------$bottom = <<< html</td></tr></table></body>html;?>

Ok, so in this you have two variables. The first being the 'top' part of your layout. This would be everything before your 'pure content' areas. The second variable is the 'bottom' part of your layout. This would be everything after your 'purecontent' area. So in short it would look like this.

$top
content
$bottom

Now here is where what you want comes into play. You can echo your entire layout around your content like this.

<html><?php include ("layout.php");echo $top;?>Put your content here!!!<?phpecho $bottom;?></html>

I think this should work... maybe jlhaslip or another member more expierienced than me could point out any flaws if any... and I hope this is what you were looking for....

Yes, this is exactly what I wanted. Thanks, Kansuke!

sonesay

In effect what your using kansuke is a template. Thats what how I do my webpages at the moment. The only improvements that I think you can make are include the full HTML in your layout.php. That way you can contorl everything such as headings, javascripts includes, CSS. now when you need to make changes to the site you just edit the layout.php template and it will affect your whole website.when you use it you can create a page (example.php) and pass it variable specific to that page.

example.php$title$content = "example_content.php" (I always do this as in include in the actual template)include('layout.php');

So first thing you would do is create a plain HTML layout you like and set where you content and items will be. Then identifiy what changes and make place holders in your template for it. Then when you are happy with it you turn it into a PHP file being the templat you will use for all your pages.Now when you need a page or extra one you just create one and pass it the variables appropriate to it. Heres an example of my index.php page

<?phpsession_start();include('includes/db.php');$title = "Welcome";$location = "index.php";$content = "includes/home_content.php";include('_core.php');?>

and heres my tempate

<?php/*Core template==============$titleinclude('menu_list.php');$content*/$title = $title." - Si Web Portfolio";echo"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://forums.xisto.com/no_longer_exists/ xmlns=\"http://forums.xisto.com/no_longer_exists/ http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /><title>$title</title><script type='text/javascript' src='js/si.js'></script><link rel=\"stylesheet\" type=\"text/css\" href=\"main.css\" /></head><body> <!-- Begin Wrapper --> <div id=\"wrapper\"> <!-- Begin Header --> <div id=\"header\"> <div id=\"header_leftside\"></div> <div id=\"header_rightside\"></div> <div id=\"header_center\"> <div id=\"header_logo\"></div> </div> </div> <!-- End Header --> <!-- Begin sub_heading --> <div class=\"container\"> <div id=\"sh_center\"> <div id=\"sh_block\"> <img src=\"images/si_15.png\" alt=\"\" /> </div> </div> <div id=\"sh_left\"></div> <div id=\"sh_right\"></div> </div> <!-- End sub_heading --> <!-- MAIN CONTENT --> <div id=\"content_container\"> <div id=\"leftsidebar\" class=\"leftbar\"> <div id=\"left_nav_container\"> <ul class=\"navigation\">"; // include menu list include('menu_list.php'); echo" </ul> </div> <div id=\"left_nav_footer\"></div> </div> <div id=\"maincontent\" class=\"centerbar\"> <div id=\"center_content\">"; // include Content if($content != "") include($content); else { // default notice echo"<h1>No content</h1>"; echo"<p>"; echo"There has been no content added in this section yet. Please return back later at a later date. Thank You!"; echo"</p>"; } echo" </div> <div id=\"si_closing\"><img src=\"images/si_closing.png\" alt=\"\" /></div> </div> <div id=\"rightsidebar\" class=\"rightbar\"> </div> </div> <!-- MAIN CONTENT END --> <!-- Begin Footer --> <div id=\"footer_container\"> <div class=\"footer_centerbar\"> </div> <div class=\"footer_leftbar\"> </div> <div class=\"footer_rightbar\"> </div> </div> <div id=\"footer_notice\"> <a href=\"http://forums.xisto.com/no_longer_exists/ src=\"http://www.w3.org/Icons/valid-xhtml10-blue; alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a> </div> <!-- End Footer --> </div> <!-- End Wrapper --></body></html>";?>

Hope this gives you some ideas on how to do things. Theres always more then one ways to do something but what ever is easier for you and works should be good enough. This is the method I have just picked up while doing websites. I used to copy and paste the whole layout to each page not too long ago lol.


KansukeKojima

Yes, this is exactly what I wanted. Thanks, Kansuke!

You arrrr welcome..... let me know if it works or not... I hope it does...
(by the way: you owe me your soul!)