...

View Full Version : PHP dynamic titles



M.W.S.
05-18-2008, 09:04 PM
Hello, I need help in dynamic titles. I'm buliding a CMS and I have structure in which the news function is going after body tag, so I can't give a title variable to <title></title>.
So what to do? :confused:

_Aerospace_Eng_
05-18-2008, 09:07 PM
Could you grab the title from the url?

M.W.S.
05-18-2008, 09:13 PM
How? I usually use just id-s in url (site.com?id=1)

dniwebdesign
05-18-2008, 09:18 PM
If you have a complete header that you include to all the files you can add an if-else (or catch-switch) statement to echo out a header depending on the page id.



<?php
$titlePrefix = "SiteNews";
if($_GET["id"]==1) {
$title = "News";
}
elseif($_GET["id"]==2) {
$title = "Downloads";
}
$newTitle = $titlePrefix." :: ".$title;

//You can output the title from php depending on where you have this code located.
//Or you can output it in the html as below.
echo "<title>$newTitle</title>";

?>

<title><?php echo $newTitle; ?></title>



Thus when you visit site.php?id=1 the page title should be "SiteNews :: News".

syosoft
05-19-2008, 02:43 AM
You might want to rethink your file structure.

If you load your page in a buffer, and then load your template, all of your page variables could be available to your template..

I wrote up a little template system tutorial that illustrates something similar: http://www.codingforums.com/showthread.php?t=139974

abduraooft
05-19-2008, 07:55 AM
We had a specific thread on this, see Dynamic <title></title> depending on page (http://www.codingforums.com/showthread.php?t=129123)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum