Page 1 of 1

Change document title

Posted: Thu Jan 22, 2009 5:24 pm
by wheatleyweb
Hello all,

Nooberiffic here. Just trying to utilize PHP for the first time. I'm not doing anything "real php-like" at this point. Having a bit of a problem using the include construct, and page titles. So I'm building a site utilizing include to append the header and footer to each content page. Working wonderfully.

However, I'm implementing site search functionality via "free find" and I'm having an issue with the returned results. They all have the title defined on header.php. The search results are correct and works wonderfully, it just doesn't look appealing when every result has the same title. So I first tried to tackle this in JS and it worked to change the title onload of each content page, but not in the results. So then I tried to tackle this via PHP and thought I had something that would work, but I can't seem to make it happen. Any light you guys could shed on this would be much appreciated. This is my first attempt with PHP and the site is not DB-driven.

Here is the PHP I've tried...

...in header.php...

Code: Select all

<title><?php echo $pageTitle?></title>
...in each content.php...

Code: Select all

<?php
$pageTitle = "Whatever you want the page title for this page to be";
?>
The result is an empty <title></title>

Thanks again

wheatleyweb

Re: Change document title

Posted: Thu Jan 22, 2009 5:36 pm
by requinix
content.php needs to include header.php after it defines $pageTitle. Have you done that?

Re: Change document title

Posted: Thu Jan 22, 2009 5:43 pm
by wheatleyweb
Perfect! I had just figured it out. Just put it together that I had the include before defining the variable. Man I'd been struggling with that for days.

Thanks for the quick reply.

I can't wait to dig in deeper to this language.