【问题标题】:multiple page titles with one header file一个头文件的多个页面标题
【发布时间】:2012-05-28 06:20:45
【问题描述】:

我有一个标题文件,它包含在我的所有其他页面中。我想知道如何使用相同的页眉有不同的页面标题。我正在使用 PHP 和 MySql。谢谢!

【问题讨论】:

    标签: php html css header include


    【解决方案1】:

    从包含中取出标题标签并将其放在页面中,似乎迫使您做出变通方法

    【讨论】:

      【解决方案2】:

      在每个特定页面上,添加$pgName = 'Page Title'; 来为每个页面命名。然后在此代码之后,include() 标头正常。在头文件中,在<head>标签中添加:

      <title><?php if(isset($pgName) && is_string($pgName)){echo $pgName;}else{echo 'Default title';} ?></title>
      

      【讨论】:

        【解决方案3】:

        将标题存储在变量中,例如

        $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>
        ...
        

        【讨论】:

          猜你喜欢
          • 2017-09-26
          • 2016-01-03
          • 2012-03-07
          • 1970-01-01
          • 1970-01-01
          • 2010-09-06
          • 1970-01-01
          • 2019-09-05
          • 1970-01-01
          相关资源
          最近更新 更多