我将几个网站从HTML转换为PHP用于动态元素,并且已经能够使用PHP和包含(使用php include())这样做。然而,我很困惑如何做头部。这就是我与纯HTML:用PHP写作头部分
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="Liberty Resource Directory. The ultimate curated directory to find what you need."/>
<meta name="keywords" content="ethan glover, lrd, liberty resource directory"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title>Liberty Resource Directory</title>
</head>
我可以轻松地添加HTML5Shim脚本,元字符集,视(是的,我将删除最大规模)和样式表的链接。
这里的问题:
我怎么能写我可以通过一个单独的页面描述,关键字和标题给它的方式PHP文件? (这样我可以把上面的代码放在一个php文件中,并将其包含在每个页面中。)
或者我只需要排除描述,关键字和标题,并且每次都重写那些部分?
这里的答案:(亚历Arbiza提供)
head.php
<head>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<meta charset="UTF-8" />
<meta name="description" content="<?php echo $description;?>"/>
<meta name="keywords" content="<?php echo $keywords;?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../stylesheets/lrdstylesheet.css" rel="stylesheet" media="screen">
<title><?php echo $title;?></title>
</head>
的index.html(包括上面的代码)
<?php
$description="Liberty Resource Directory. The ultimate curated directory to find what you need.";
$keywords="ethan glover, lrd, liberty resource directory";
$title="Liberty Resource Directory";
include 'scripts/head.php';
?>
的最终结果:
http://libertyresourcedirectory.com/
你可以使用include里面的'
<?php include'file.php'; ?>' - 对于单个页面描述等,需要多一点编码,*我害怕*。改用框架;它会更容易。 – 2014-09-24 17:12:05发布您的PHP代码。你使用任何框架或裸骨头的PHP? – 2014-09-24 17:12:59