Cod*_*key 9 html php templates templating
所以,我正在建立一个关于第一次世界大战的网站作为学校作业,我希望它出现在每个文件中:
<!DOCTYPE html>
<html>
<head>
<title>1914</title>
<script src="modernizr-1.5.js"></script>
<link href="styles.css" type="text/css" rel="stylesheet" />
<meta charset="utf-8" />
</head>
<body>
<div id="container">
<header>
<img src="images/banner.png" alt="World War I" style="border: none"/>
<nav>
<ul>
<a href="index.htm"><li><span>Home</span></li></a>
<a href="1914.htm"><li><span>1914</span></li></a>
<a href="1915.htm"><li><span>1915</span></li></a>
<a href="1916.htm"><li><span>1916</span></li></a>
<a href="1917.htm"><li><span>1917</span></li></a>
<a href="1918.htm"><li><span>1918</span></li></a>
</ul>
</nav>
</header>
<section>
<article>
<br style="clear: both" />
</article>
<aside>
</aside>
</section>
<footer style="font-weight: bold; letter-spacing: .1em">
<a href="citations.htm">Citations</a> •
<a href="about.htm">About</a>
</footer>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我认为将所有这些复制粘贴到每个文档中都是一种愚蠢的做法,如果我只想更改一个单词或标记,那就费力地单独更改每个页面.有没有办法我可以把它放在template.htm(或类似的东西),并有PHP或javascript代码采取这个并插入<article>标签内的请求文件中的所有内容?我不知道很多php,所以这对你的大师来说可能是件小事,但我会很感激帮助.
Ric*_*der 21
使用php包括:
将其保存为top.php
<html>
<head>
<title><?php echo $title; ?></title>
<script src="modernizr-1.5.js"></script>
<link href="styles.css" type="text/css" rel="stylesheet" />
<meta charset="utf-8" />
</head>
<body>
<div id="container">
<header>
<img src="images/banner.png" alt="World War I" style="border: none"/>
<nav>
<ul>
<a href="index.htm"><li><span>Home</span></li></a>
<a href="1914.htm"><li><span>1914</span></li></a>
<a href="1915.htm"><li><span>1915</span></li></a>
<a href="1916.htm"><li><span>1916</span></li></a>
<a href="1917.htm"><li><span>1917</span></li></a>
<a href="1918.htm"><li><span>1918</span></li></a>
</ul>
</nav>
</header>
<section>
Run Code Online (Sandbox Code Playgroud)
将其保存为bottom.php
<aside>
</aside>
</section>
<footer style="font-weight: bold; letter-spacing: .1em">
<a href="citations.htm">Citations</a> •
<a href="about.htm">About</a>
</footer>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后您的个人页面将是这样的:
<?php $title = '1914'; include("top.php");?>
//This would be where you would make the changes that need to be made on each page.
<article>
<br style="clear: both" />
</article>
<?php include("bottom.php");?>
Run Code Online (Sandbox Code Playgroud)