You are here: Home > Useful Guides > Step 3) Creating The Files - Part 3
Friday, 05 September 2008
So far we've got our template files laid out. We've got a sparse CSS file and we've got the basic pages required, empty but ready to roll.
The first thing to do is fill in the static files: terms, privacy, disclaimer, contact, about.....
You can do this following this file structure:
<?php$pagetitle is used to define the H1 tag on the page along with the title tag in the head section on the html. $pagekeywords lends itself nicely to the keywords tag and thus the description tag also works in the same manor.
$pagetitle="Page title goes here";
$pagekeywords="list, keywords, here";
$pagedescription="Write a page description here";
include "includes/head.php";
echo "<h1>".$pagetitle."</p>";
echo "<p>Page text goes here</p>";
include "includes/foot.php";
?>
ErrorDocument 404 /404.htmlEvery server is different so your server may handle this differently. For me, it redirects all ".html" queries to a physical ".php" page on the server. The first line also says to redirect (ultimately to 404.php) if a 404 error occurs.
RewriteEngine On
RewriteBase /
RewriteRule ^(.*).html$ $1.php [L]
User-agent: *I've put both variations of the page in there just in case. If you get stuck, check this robots.txt guide.
Disallow: /go.html
Disallow: /go.php
<?phpHere's the walthrough:
header("Content-type: text/xml");
include "includes/connect.php";
$sql1 = "SELECT id,name FROM recipe ORDER BY date DESC LIMIT 10";
$result1 = mysql_query($sql1) or die(mysql_error());
$rowcounter1 = mysql_num_rows($result1);
echo "<?xml version='1.0' encoding='iso-8859-1' ?>";
echo "<rss version='2.0'><channel>";
echo "<title>Latest Recipes From My Recipe Site</title><link>http://www.mydomain.com/</link><description>Get
baking with our 10 latest recipes</description>";
if ($rowcounter1 > "0")
{
while ($row1 = mysql_fetch_array($result1))
{
extract($row1);
echo "<item><title>".$name."</title><link>http://www.mydomain.com/recipe-".$id."-".strtolower(str_replace("
","-",$name)).".html</link><guid>http://www.mydomain.com/recipe-".$id."-".strtolower(str_replace("
","-",$name)).".html?q=".$id."</guid><description><![CDATA[<p>Discover how to cook a ".$name."</p>]]></description></item>";
}
}
echo "</channel></rss>";
?>
RewriteRule ^recipe-(.*)-(.*).html$ recipe.php?recipe=$1 [L]This enables the fancy URL structure discussed in rss.php.
<?phpRemember to add the template variables.
include "includes/head.php";
include "includes/connect.php";
$recipereference=explode("-",$_GET['recipe']);
$recipeid=$recipereference[0];
if (!is_numeric($recipeid)) {$recipeid=0;}
$sql1 = "SELECT * FROM recipe WHERE id='".$recipeid."' ORDER BY date DESC
LIMIT 6";
$result1 = mysql_query($sql1) or die(mysql_error());
$rowcounter1 = mysql_num_rows($result1);
if ($rowcounter1 == "1")
{
extract(mysql_fetch_array($result1));
echo "<p>".$name."</p>";
} else {
echo "<p>Sorry, we cannot find that recipe.</p>";
}
include "includes/foot.php";
?>
Bookmark this article in Bumpzee, Del.icio.us, Digg and Stumble Upon
Technorati tags: htaccess, robots, php, mysql
You may also be interested in reading:
Care to Comment?Comments are manually approved and hence can a while to appear. Questions, informative posts, and feedback comments are gladly accepted. Spam is deleted. Spam-type comments have their links removed (Comment Policy)
Please allow 1 minute to connect. Please quote code DF
2008:
2007:
Freebies make me work harder! If you send it, I'll blog about it - unless it's rude :-)
