[thelist] Dynamic Title / Meta
Frank Marion
lists at frankmarion.com
Mon Jul 26 15:37:43 CDT 2010
On 2010-07-26, at 10:08 AM, DAVOUD TOHIDY wrote:
> Thanks a lot that worked. I do appreciate it.
>
> @ Benjamin: your solution unfortunately did not work. However I do
> appreciate your input.
I've had that issue before, when using an old version of fusebox. One
trick I sometimes resort to, when doing a quickie "page based" site,
is to do this (hope the pseudocode is understandable):
Create your content page "myPage.php"
pageTitle = "My page title"
pageKeywords = "these,are,key,words"
pageDescription = "This is the meta description for my page"
pageContent="
page content goes here
page content goes here
page content goes here
"
Have a separate file for your template, having the various pieces
chopped up into variables.
myTemplate.php
templateTop="
/* -----------------------------*/
<html>
<head>
<title>$pageTitle</title>
<meta ..... />
</head>
<body>
/* -----------------------------*/"
templateBottom="
/* -----------------------------*/
</body>
</html>
/* -----------------------------*/"
I don't know what can and cannot be done with PHP, but I'm sure that
you can do file reads and set the contents to variables, so you'd need
only need to edit you template in one file, yet, all your separate
content pages get pieced together with the final output as such:
index.php
$templateTop
$pageContent
$templateBottom
The nice part about this is that you can control all kind of elements
by adjusting variables at the top of your content page.
A cheap way of accessing it is to name your pages consistently
"myPage.php", "aboutUs.php", "contactUs.php" then link like this:
index.php?goto=aboutUs
where your index file has
set thePage =
if isDefined($goto & ".php") {
include($goto & ".php")
$templateTop
$pageContent
$templateBottom
} else {
$templateTop
404 page not found message
$templateBottom
}
and output $thePage
There are way more elegant ways of doing things than this, but as a
starter way of thinking it's effective. You can eventually figure out
that you don't need to have content pages, and can pull stuff from a
database.
If you're sort of new at programming, may I recommend that you learn a
framework? A framework is just a general blue print, or way of
thinking of code and file organization to help stay clean, crisp and
steer clear from spaghetti code. The above is a very simple example.
I've found that a pre-created framework is a good way to structure my
mind. One of the benefits of learning some framework is that the
issues that one encounters frequently have usually been recognized and
addressed.
Some frameworks you might want to look into:
Model-View-Controler (though technically speaking, it isn't a
framework, it's a way of thinking)
CodeIgniter
Symfony
Fusebox
Google "PHP framework".
--
Frank Marion
lists [_at_] frankmarion.com
More information about the thelist
mailing list