20 June 2006

Dynamic Page Title

Well, did you ever build a webpage that had only one header? I mean you include a header page in every page? Something like this:

index.php (or any other page)

This is a nice way of building a simple web page. You only have 1 header, 1 footer, probabli 1 menu, so you don't have to edit 100 HTML files. But the probleh ere si that you have only 1 page title, bechose you have only 1 header. So, as I was reading trough tutorials around the web, tutorials about SEO (Search Engine Optimization), i'v read that it's good to have a uniq page title for every page. For example, if your name is BOB and you have a page about fish, your normal page title is Bob's WebPage, on the fish page you want to have something like: Bob's WebPage - Fish, etc.

So I tryed diferent methods how to do a Dynamic Page Title. Some people around SitePoint Forums helped me, so I'm sharing this with you.

On your page header in the TITLE tag put this:
< ? p h p if (defined ('TITLE')) {
print TITLE;
} else {
print 'YourSite.com';
Then, on your index page put this:
< ? p h p define ('TITLE', "YourSite.com - Homepage"); include_once("pageheader.php"); ?>
Normaly you will only add include_once("pageheader.php"); but since you want a dynamix page title you add the "define".
That like will "define" your page title as: YourSite.com - Homepage. If you don't att the "define" like on your page the "default" title will be displayed.

On another page you add this:
< ? p h p define ('TITLE', "YourSite.com - About Us"); include_once("pageheader.php"); ?>

Got the ideea? If not, ask a question.

Thanks to people around SitePoint Forums for helping me with this.

EDIT: It seems blogger is STUPID and he ALWAYS interpetates HTML, even on the "compose" part. IT SUKS. Also on the "compose" part the HTML part starts to get UGLY, and i can't fix it coz my "code" will dissapear.

EDIT2:It also seems that the text < ? p h p don't appear.


Post a Comment

<< Home