Forum Moderators: coopster
Can I create another variable, say $content and then have all three of them identified within each page?:
<?php
$title = "homepage"
$description = "what page is about"
$content = {
<html line1>
<html line2>
...etc (html lines 3-100)
}
?>
Or is this even possible?
What I am currently using is an Include statement to input the entire page, so I'm not sure how to involve the $title and $description variables into it:
a href="index.php?page=home">home</a>
a href="index.php?page=about">about</a>
Credit goes to forum member "Distel" for the following code:
<?php
if(isset($_GET['page'])) {
include("{$page}/index.php");
print($page);
}
else {include('home/index.php');
}
?>
So what is the easiest way to dynamically call the $title and $description variables and where should I store them?
call it at the top of each page you wish to change....
then where the title is you could do it this way
<title> <? echo $mytitle;?> </title>
<?php
function do_html_head($title,$keywords,$description)
{
// print an HTML head
?><!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?>">
<META NAME="description" CONTENT="<?php echo $description?>">
}
And then I apply it on the page where I need it like:
<?php
do_html_head('title text','keywords text','description text');
?>
<?php
do_html_head('Welcome to Clyde's Used Camels','used camels, camel humps','we specialize in used camels both one and two hump');
?>
I do not see the advantage. you'd have to call the function first thing on the page, otherwise it would not be on top. Might as well write the headers in there right away on the page and make the included header shorter. The savings between the function, the execution time, etc. seem to be minimal.
or am i missing something?
currently I use the actual file name to create title and headers on the fly. I use php_self and it seems to work. albeit I would love to have better description tags ...
<? php
$title = 'page title here';
$desc = 'page description';
$key = 'keywords';
$robots = 'index, follow';
?>
and simply using an include to get the variables into the template page:
<?php if(isset($_GET['page'])) {include("{$page}/head.php");} else {include('home/head.php');}?>
and plugging them into the title, description, etc.:
<title><?php echo "$title";?></title>
<meta name="description" content="<?php echo "$desc";?>" />
<meta name="keywords" content="<?php echo "$key";?>" />
<meta name="robots" content="<?php echo "$robots";?>" />
My initial goal was to be able to declare these variables within the content document without having to create a seperate head.php document for each page, but I couldn't figure out a way to do it.
So what do you think? Is there a better or more efficient way that I should know about before I begin making all of these header documents?
This is in my template page before the <head>:
<?php $x=head; if(isset($_GET['page'])) {include("{$page}");} else {include('home/index.php');}?>
This is in the template page <head>:
<title><?php echo "$title";?></title>
<meta name="description" content="<?php echo "$desc";?>" />
<meta name="keywords" content="<?php echo "$key";?>" />
<meta name="robots" content="<?php echo "$robots";?>" />
And this is in the template page <body> where you want your content:
<?php $x=body; if(isset($_GET['page'])) {include("{$page}");} else {include('home/index.php');}?>
Notice the $x variable determining head versus body content. Then I simply made my includes pages as follows:
<?php
$title = 'my page';
$desc = 'page description';
$key = 'keywords;
$robots = 'index, follow';
if ($x==head) {return;}
?>
<!-- begin content below -->
This solution allows you to declare your page header info right within your content pages. Hopefully this may come in handy for someone.
[edited by: CNibbana at 3:45 am (utc) on April 28, 2004]