<;头部>;标签


HTML metadata after <head> tag

我正在创建一个PHP网站,该网站有一个index.PHP文件,而不是一些文件。PHP、about.PHP、contact.PHP,我将其设置为:index.PHP?p=什么,index.php?p=接触等

目前我的index.php代码如下:

<head>
   <title>Something</title>
   <link href="theme.css" rel ="stylesheet" media="screen">
</head>
<body>
<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
</body>

现在的问题是,我想在index.php、something.php和about.php中有不同的元数据。我知道我必须在<head></head>之间添加元数据,但稍后会包含something.php和aboutphp。如何为文件提供不同的元数据?是否可以在<head></head>标记之后(重新)设置元数据?

我不知道,我理解你的问题吗,但当然,你也可以在标题中使用if条件!

<head>
    <title>Something</title>
    <link href="theme.css" rel ="stylesheet" media="screen">
    <?php
        if ($_GET["p"] === 'something') {
            ?>
    <!-- Write your metadata here if the page is something... -->
    <?php
        } elseif ($_GET["p"] === 'about') {
        ?>
    <!-- Write your metadata here if the page is about... -->
    <?php
        }
    ?>
</head>
<body>
    <?php
    if ($_GET['p'] == 'something') {
        include 'pages/something.php';
    } elseif ($_GET['p'] == 'about') {
        include 'pages/about.php';
    }
    ?>
</body>

尝试根据您的偏好加载元数据,例如:

<head>
   <title>Something</title>
   <link href="theme.css" rel ="stylesheet" media="screen">
   <?php if (@$_GET['p'] == 'something') echo "<meta charset='utf-8'>"; ?>
</head>
<body>
<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
?>
</body>

在index.php 中

<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
?>

在您的about.phpsomething.php中包括完整的html页面,它的标题标签