We include a header.php file across all the pages on our site. So we could either place a single title in the header.php file which would be applied to the entire site, or have a custom header within each page to be more descriptive.
The problem is that in doing that, the title would be outside the head tags (which remain in the header.php file) and marked as invalid.
Is there some kind of function we can use to define a variable ($pageTitle) within the page, that will be displayed in head tag?
Thanks.
Actually it should be this way
news.php:
<?
include "config.php"; //connect to database HERE.
$data = getdbdata("SELECT * FROM news where id = %d",$_GET['id']);
$page_title = $data['title'];
$body = nl2br($data['body']);
$tpl_file = "tpl.news.php";
include "template.php";
?>
template.php:
<html>
<head>
<title><?=$page_title?></title>
</head>
<body>
<? include $tpl_file ?>
</body>
tpl.news.php
<h1><?=$page_title?></h1>
<?=$body?>
plain and simple
Ummm.....
<?php
$pageTitle = "Test";
include('header.php');
?>
EDIT
Then in your header.php
<head>
<title><?php echo $pageTitle; ?> </title>
</head>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With