我们在网站的所有页面中包含一个 header.php 文件。因此,我们可以在 header.php 文件中放置一个标题,该标题将应用于整个站点,或者在每个页面中添加一个自定义标题以更具描述性。
问题是,这样做时,标题将位于 head 标签之外(保留在 header.php 文件中)并被标记为无效。
我们是否可以使用某种函数来定义页面内的变量($pageTitle),该变量将显示在 head 标签中?
Thanks.
其实应该是这样的
新闻.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";
?>
模板.php:
<html>
<head>
<title><?=$page_title?></title>
</head>
<body>
<? include $tpl_file ?>
</body>
tpl.news.php
<h1><?=$page_title?></h1>
<?=$body?>
干净利落
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)