我正在创建一个有一个index.php文件的PHP网站,而不是文件something.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和about.php。如何为文件设置不同的元数据?是否可以在<head></head>
标签之后(重新)设置元数据?
答案 0 :(得分:1)
<?php
if (@$_GET['p'] == 'something') include 'pages/something.php';
elseif (@$_GET['p'] == 'about') include 'pages/about.php';
?>
在您的about.php
中,something.php
包含完整的html页面,其中包含头标记
答案 1 :(得分:1)
我不知道,我是否理解你的问题,但当然,你也可以在标题中使用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>
答案 2 :(得分:1)
尝试根据您的偏好加载元数据,如下:
<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>