Forum Moderators: coopster
I seem to be making hard work of this somehow, hope someone can help.
I am developing a php site template. A single index page and the content changes depending on which link is clicked - pretty standard stuff I think and that part works quite well. However, at the begining of each content page I intended to store the relevant $title and $keyword information, such that header info will change to include these. Following is the basis of my template page [index.php]. page1.php would include the $title and $keyword variables. I have removed as much irrelevant code [banner, footer, sidebar etc.] as possible.
<?php
$page = ($_GET['page']);
if (empty($page))
{
$page = 'includes/content/page1.php';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title><?php echo $title;?></title>
<meta name="keywords" CONTENT="<?php echo $keywords?>">
<link href="./styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main">
<div id="content">
<?php
if(file_exists($page))
{
include ($page); // Page content
}
else
{
echo "Page temporarily unavailable";
}
?>
</div><!--end content-->
When the links on the page are clicked, the content changes but the title and keywords remain blank.
Can someone point out the flaw in my logic, or is there a better way to do this?
Many thanks in advance.
you have not included the file in any way before you try to echo out the title and keywords.
you need to put the include statement above the html output
if(file_exists($page))
{
include ($page); // Page content
}
<html>
...
and as long as you have assigned the $title and $keywords variable it should echo it out correctly.
to echo out the content in the correct place, assign your content to a variable in the page.php
e.g.
$content = '<p>hallo buy my widget</p>';
then echo $content between the body tags, just like the title
hth