Forum Moderators: coopster

Message Too Old, No Replies

Template interfering with title tag

I want each page to have it's own title

         

chambers

2:24 am on Jul 1, 2007 (gmt 0)

10+ Year Member



I'm currently using a template system for my site. The way it's currently set up means all the pages have the same title. I want to change this so that each page has it's own title.

template.php

<?php
header("Content-type: text/html; charset=utf-8");

include("index_header.inc");

if (!isset($_GET['p'])) {

include("404.php");

} else {

include("main/" . $_GET['p'] . ".php");
}

include("index_footer.inc");
?>


index_header.inc

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css"><!-- @import url(_blah.css); --> </style>

<title>Blah Blah</title>

<?php
include 'database_stuff.php';
include 'database_stuff.php';
include '_stuff.inc';
?>

</head><body>

<div align="center">

<div id="logo"> </div>

<div id="holder" align="left">
<div id="menu">

** The menu, which shows up on every page and is floated to the right so comes before the content.**
</div>
<div id="content">


I first thought I could declare the title in each page and then simply call it up in the title tags.

[quote]<title> <?=$title;?> </title>
[/quote]

But because the content page is processed after the index_header page, the title has no value.

I'm stumped about what to do.

venelin13

6:04 am on Jul 1, 2007 (gmt 0)

10+ Year Member



The page title should be set prior the index_header.inc is included:


$title = "My Page Title";
include('index_header.inc');

Since you want each page to have its own title, you shouls have a way to determinate the page title by the page name - $_GET['p']

Just a very simple example:


$title = ucfirst($_GET['p']);
include('index_header.inc');

Or if you have an array of page/title pairs:
$page_titles = array("about"=>"About us page", "index"=>"Welcome", "contact"=>"Contact us");

and $_GET['p'] = "about";


$title = $page_titles[$_GET['p']];
include('index_header.inc');

chambers

7:05 pm on Jul 1, 2007 (gmt 0)

10+ Year Member



Thanks for the suggestions. I thought I was going to have to re-write the template, but I used the array method in the end.