View Full Version : PHP dynamic titles
05-18-2008, 10: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:
05-18-2008, 10:07 PM
Could you grab the title from the url?
05-18-2008, 10:13 PM
How? I usually use just id-s in url (site.com?id=1)
05-18-2008, 10: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.
$titlePrefix = "SiteNews";
$title = "News";
$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.
<title><?php echo $newTitle; ?></title>
Thus when you visit site.php?id=1 the page title should be "SiteNews :: News".
05-19-2008, 03: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
05-19-2008, 08:55 AM
We had a specific thread on this, see Dynamic <title></title> depending on page (http://www.codingforums.com/showthread.php?t=129123)
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.