Log in

View Full Version : Need Help: PHP for dynamic page titles



brandonjp
08-27-2007, 04:30 PM
I've read other posts on here and have tried to simplify the code, but am having problems:

I've got a page - index.php - within that page is a hard coded header & footer with a php function that calls up another page - for example: default.php

Header
default.php
Footer

No problems...except I'd like the page titles to reflect the content from default.php

I tried by putting this in the <head> tag of index.php:
<title><?php echo($title);?> - MyFantasticWebPage.com</title>

And putting this in default.php:

<?php
$title = "Casino Chair";
?>

but it didn't work....can some steer me in the right direction?
My actual page example is here: http://www.fiberartfurniture.com/collections/index.php?c=LE0706JC

Thanks
--bp

thetestingsite
08-27-2007, 06:59 PM
In order for your above code to work, you need to call default.php first before calling you can echo the variable $title. The reason for this is because you need to define the variable (in this case, $title) before you can echo it. In index.php, is the header and footer in a variable, function, or some other sort of item that can be called after default.php is included? If not, you may want to think about doing it this way instead of the way you are currently doing it.

Hope this helps.