【发布时间】:2012-05-28 06:20:45
【问题描述】:
我有一个标题文件,它包含在我的所有其他页面中。我想知道如何使用相同的页眉有不同的页面标题。我正在使用 PHP 和 MySql。谢谢!
【问题讨论】:
标签: php html css header include
我有一个标题文件,它包含在我的所有其他页面中。我想知道如何使用相同的页眉有不同的页面标题。我正在使用 PHP 和 MySql。谢谢!
【问题讨论】:
标签: php html css header include
从包含中取出标题标签并将其放在页面中,似乎迫使您做出变通方法
【讨论】:
在每个特定页面上,添加$pgName = 'Page Title'; 来为每个页面命名。然后在此代码之后,include() 标头正常。在头文件中,在<head>标签中添加:
<title><?php if(isset($pgName) && is_string($pgName)){echo $pgName;}else{echo 'Default title';} ?></title>
【讨论】:
将标题存储在变量中,例如
$title = 'Main title';
if($page == 'this page has a different title') {
$title = 'A different title';
}
include 'header.php';
在 header.php 集合中
<head>
<title><?php echo $title; ?></title>
...
【讨论】: