And*_*las 3 php metadata title
我们在网站的所有页面中都包含一个header.php文件.因此,我们可以在header.php文件中放置一个标题,该文件将应用于整个网站,或者在每个页面中都有一个自定义标题,以便更具描述性.
问题是,在这样做时,标题将位于head标签之外(保留在header.php文件中)并标记为无效.
我们可以使用某种函数在页面中定义一个变量($ pageTitle),它将显示在head标签中吗?
谢谢.
实际上它应该是这样的
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";
?>
Run Code Online (Sandbox Code Playgroud)
的template.php:
<html>
<head>
<title><?=$page_title?></title>
</head>
<body>
<? include $tpl_file ?>
</body>
Run Code Online (Sandbox Code Playgroud)
tpl.news.php
<h1><?=$page_title?></h1>
<?=$body?>
Run Code Online (Sandbox Code Playgroud)
干净利落
| 归档时间: |
|
| 查看次数: |
6855 次 |
| 最近记录: |