Page 1 of 1

Getting the Header to display different page titles

Posted: Thu Feb 18, 2010 2:59 pm
by alex.saidani
I have written a script for my website's header that is completely seperate to all the pages, this was to make it easier for me to edit the header, rather than going into every page. However the problem is i can only get this script to dispaly one title for every single page. I was just wondering if anyone could offer any help on how to get the header to display a different title for each page.
Thanks in advance :)

Re: Getting the Header to display different page titles

Posted: Thu Feb 18, 2010 3:15 pm
by pickle
A couple ways:

1) In your header script, you could figure out the filename of the current page (something like: basename($_SERVER['REQUEST_URI']) could work). Then display a particular title depending on the filename

2) A more flexible way would be to include the title of the page in the file that is including the header script:

Code: Select all

<?PHP
$title = "This is my blog";
include "header.inc";
 
... rest of the page
?>
Then have your header.inc file work with $title.

Re: Getting the Header to display different page titles

Posted: Thu Feb 18, 2010 5:35 pm
by alex.saidani
Thanks for the help, i intended to put the title part inside the header.
This is what i tried, did not work though, i clearly am doing something wrong :/

Code: Select all

 
<title>
<?php 
$title= basename($_SERVER['REQUEST_URL'])
if ($title == "index.php") {
   echo "Moovie :: Home"; 
   } 
?>   
</title>
 

Re: Getting the Header to display different page titles

Posted: Thu Feb 18, 2010 5:46 pm
by pickle
It's REQUEST_URI (you-are-eye) not URL (you-are-ell)

Please use [syntax=php][/syntax] tags when posting PHP code.