Jump to content
xisto Community
tricky77puzzle

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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/

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.