Forum Moderators: coopster
I have a html template that I want to convert to PHP so I can use a single template rather than 1 template for each body file.
here is the sample PHP file I found:
<?php
$header = "header.html";
$footer = "footer.html";
$file = $_SERVER["PATH_TRANSLATED"];
readfile($header);
readfile($file);
readfile($footer);
?>
Here is my current html file [notice I have 4 includes and use CSS to layout the includes in DIV sections]
My current page can be found at <snip> However as I make this new template I will be changing the layout:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>Amazing Hands Therapeutic Massage (Massage Therapy New Orleans)</title>
<link rel="stylesheet" type="text/css" href="amazinghandsdefaultheader1.css">
<style type="text/css">
table.c19 {width: 100%;}
td.c18 {height:48px; text-align: right; vertical-align: top;}
img.c17 {width: 44px; height:46px;}
td.c16 {height: 48px; text-align: left; vertical-align: top;}
img.c15 {width: 34px; height: 46px;}
td.c14 {height:48px; vertical-align: middle; text-align: right;}
td.c13 {height: 48px; text-align: center; vertical-align: middle;}
td.c12 {width:100px;height: 48px; text-align: center; vertical-align: middle;}
img.c11 {width: 540px; height: 360px;}
td.c10 {text-align: left; vertical-align: top;}
table.c9 {text-align: left; width: 100%;}
span.c8 {font-style: italic;}
div.c7 {text-align: center}
table.c6 {text-align:left; background-color:#FFCC66; width:100%;}
td.c5 {vertical-align: top;}
p.c4 {font-size: 10px; text-align:justify}
h1.c3 {margin-top: 0PX;margin-bottom: 0PX;}
td.c2 {vertical-align: top; width: 100px;}
img.c1 {width: 96px; height: 98px;}
</style>
</head>
<body>
<div id="bodyarea">Best viewed with Firefox or IE 7
<div id="headerarea"><!--#include virtual="header.html"--></div>
<div class="c7" id="leftcol"><!--#include virtual="menu.html"--></div>
<div id="contents"><!--#include virtual="body/main.html"--></div>
<div id="footer"><!--#include virtual="footer.html"--></div>
</div>
</body>
</html>
[edited by: eelixduppy at 4:49 pm (utc) on Dec. 3, 2007]
[edit reason] no URLs, please [/edit]
For example using your html:
PAGE (somename.php)
<?php
$title = "Amazing Hands Therapeutic Massage (Massage Therapy New Orleans)";
$content = "whatever";
// other variables as required
require("/includes/template.inc");
?>
TEMPLATE (template.inc)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title><?php print $title;?></title>
<link rel="stylesheet" type="text/css" href="amazinghandsdefaultheader1.css">
<style type="text/css">
<!-- if needed -->
</style>
</head>
<body>
<div id="bodyarea">Best viewed with Firefox or IE 7
<div id="headerarea"><!--#include virtual="header.html"--></div>
<div class="c7" id="leftcol"><!--#include virtual="menu.html"--></div>
<div id="contents"><?php print $contents?></div>
<div id="footer"><!--#include virtual="footer.html"--></div>
</div>
</body>
</html>
You don't actually need to really know PHP in any depth. Just pick up the commands you need as you go along.
I am kinda thinking it should be in the htaccess file. As a wrapper....
i.e.
http:/ / webpage. blah/indexprices.html#specials
where the actual indexprices.html file would just contain the html for the page and the header, menu, and footer would be wrapped via php called from htaccess.
Actually I may have just answered my own question below
$content = "whatever";
would be
$content = $_SERVER["PATH_TRANSLATED"];
and in htaccess use:
AddHandler headered .html
Action headered /header/somename.php
-- would there be a way to call the title from this "actual html document"? Not that it matters...
You see it on the free web servers all the time i.e. tripod, geocities or whatever they all are
You say that the title doesn't matter, and I note that all the pages on your website have the same title. The title does matter, and should be unique for each page. You should also have a unique meta description tag for each page. If you don't you are unlikely to get indexed properly in search engines.
Also you don't need to have the CSS styles in your html. You can put them in the stylesheet that you link to.
Another point is that your site can be accessed by "domain.us/" but your internal links for your home page direct to "domain.us/index.html". This means that Search Engines will probably index your home page twice as "domain.us/" and "domain.us/index.html". You need to decide on which one to use. If it is to be "domain.us/" (which is fairly normal) then your internal home page links should be "/", and you should set up a mod rewrite in htaccess so that "domain.us/index.html" is converted to "domain.us/".
I tried changing the template.inc to template.html it works the same way.
calling template.html by itself loads the includes.... hmmm
Wait if I can call my body with a php file command, why not the rest? <?php print readfile($file)?>
Don't you love it how I progress as I am giving up and writing a response.
--Pausing to test--
ok that is getting close, I just need to purge & clean the css to see if it will work. and display correctly.
--------
If this works, I'll post the htaccess, *.php and *.inc file for reference. Then anyone can use css and load any *.html onto a page wrapping it in.
There are several ways of doing this, but I set a variable on each page which is dependant on the directory level of the page.
$prefix = "../"; // or whatever
on the home page it is:
$prefix = "";
Then I code the commands in the template as:
<?php require("{$prefix}includes/whatever.inc");?>
I also use it within the template html for images:
<img src="<?php print $prefix;?>images/someimage.jpg" alt="">
I created a php wrapper using htaccess so all
pages load with the same header/footer/menu. Makes it
real easy to update now. Its like CSS did for layout
and coloring. One site calls it a tortilla wrap.
Only I replaced the readfile with an include. It gets
rid of the checksum number after the file. And SSI
includes won't work in the PHP or template.inc (not
sure about main body), but we are using PHP so I used
it for all the parts. Header/Menu/Footer/Body -- You don't
need full html just body text in each file. Head
information is only needed in the template since its
wrapped around the other pages.
I got rid of the title in the header and put it in the
actual html body file. The browser still seems to read
it. Hopefully the search engines do, otherwise, I'll
have to figure out a php solution, if there is one.
Another quark is that there are no error pages. You
would have to add that to the php if you want, but
with the menu on each page, they can easily find
there way to a working page.
Here is the code (your menu.html, header.html, footer.html go in template folder too):
.htaccess
AddHandler headered .html
Action headered /neworleans2/template/somename.php
##Note full path from top of web I WOULD LIKE TO USE
RELATIVE if someone gets it to work
template/somefile.php
<?php
$file = $_SERVER["PATH_TRANSLATED"];
// other variables as required
require("template.inc");
?>
template/template.inc
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- <title>CSS Page Template - Two Column, Left
Static</title>-->
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="NOINDEX" />
<meta http-equiv="PRAGMA" content="NO-CACHE"
/>
<link rel="stylesheet" type="text/css"
href="template/***layout.css" />
<link rel="stylesheet" type="text/css"
href="template/***presentation.css" />
<link rel="stylesheet" type="text/css"
href="template/other.css">
<style type="text/css">
<!-- if needed -->
</style>
</head>
<body>
<!-- left column -->
<div id="lh-col"><br />
<?php include("menu.html")?>
</div>
<!-- end of left column -->
<!-- right column -->
<div id="rh-col">
<?php include("header.html")?>
<?php include($file)?>
<!-- These don't work in the wrapper use the php include instead #include
virtual="template/footer.html"-->
<?php include("footer.html")?>
</div>
<!-- end of right column -->
</body>
</html>
$file = $_SERVER["PATH_TRANSLATED"];
and the template.inc calls the file.
-------------Harry Said:
<?php print readfile($file);?>
Also I would have thought that the last command could be just
<?php print $file;?>