您可以使用主页示例执行以下操作:
<?php
// put metadata inside this array
$pageData = array(
'title' => 'my page title',
'metaDataDescription' => 'my meta data for this page',
'customAssets' => array(
array(
'type' => 'js',
'src' => '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'
)
)
);
// include your header file now
require_once 'header.php';
?>
<div>
This is where the unique content or HTML for this page should go.
You could also include unique JavaScript here as well
</div>
<?php
require_once 'footer.php';
?>
然后header.php
文件可能如下所示:
<?php
// TODO add a null check for $pageData
// and fill in with defaults
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title><?php echo $pageData['title'];?></title>
<!-- add general css and js files here -->
<?php
foreach($pageData['customAssets'] as $index => $asset) {
// TODO do some code to write out custom assets
// ex:
if($asset['type'] === "js") {
echo '<script type="text/javascript" src="' . $asset['src'] . ' "></script>';
}
}?>
<!-- use php to get meta data like title, description, keywords... ex: -->
<meta name="description" content="<?php echo $pageData['metaDataDescription'];?>" />
<!-- add favicon and whatever else in the header here -->
</head>
<body>