HTML模板 - PHP? [英] HTML Templates -- php?
问题描述
<!DOCTYPE html>
< html>
< head>
< title> 1914< / title>
< script src =modernizr-1.5.js>< / script>
< link href =styles.csstype =text / css =stylesheet/>
< meta charset =utf-8/>
< / head>
< body>
< div id =container>
< header>
< img src =images / banner.pngalt =第一次世界大战style =border:none/>
< nav>
< ul>
< a href =index.htm>< li>< span>主页< / 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>
<节>
<文章>
< br style =clear:both/>
< / article>
<预计>
< / aside>
< / section>
< footer style =font-weight:bold; letter-spacing:.1em>
< a href =citations.htm>引文< / a> &安培;公牛;
< a href =about.htm>关于< / a>
< / footer>
< / div>
< / body>
< / html>
我认为将所有这些复制到每个文档中是愚蠢的,如果我只想更改一个单词或标记,请分别更改每个页面。有没有一种方法可以把它放在template.htm中(或者类似的东西),并且让php或者javascript代码把它放在< article>
标签?我不知道很多的PHP,所以这可能是你的大师的一块蛋糕,但我会很感激帮助。
使用php包括:
另存为top.php
< html>
< head>
< title><?php echo $ title; ?>< /标题>
< script src =modernizr-1.5.js>< / script>
< link href =styles.csstype =text / css =stylesheet/>
< meta charset =utf-8/>
< / head>
< body>
< div id =container>
< header>
< img src =images / banner.pngalt =第一次世界大战style =border:none/>
< nav>
< ul>
< a href =index.htm>< li>< span>主页< / 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>
<节>
另存为bottom.php
<一旁>
< / aside>
< / section>
< footer style =font-weight:bold; letter-spacing:.1em>
< a href =citations.htm>引文< / a> &安培;公牛;
< a href =about.htm>关于< / a>
< / footer>
< / div>
< / body>
< / html>
然后您的个人页面将如下所示:
<?php $ title ='1914';包括( top.php);?>
//这将是您需要在每个页面上进行更改的位置。
<文章>
< br style =clear:both/>
< / article>
<?php include(bottom.php);?>
So, I'm making a site about WWI as a school assignment, and I want this to appear in every document:
<!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>
I think it's kind of stupid to copy-paste all this into each document, and painstakingly go in and change each page separately if I just want to change one word or tag. Is there a way I can put this in template.htm (or something similar) and have php or javascript code take this and insert everything from the requested file inside of the <article>
tag? I don't know a lot of php, so this is probably a piece of cake for you gurus, but I would appreciate the help.
Using php includes:
Save this as 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>
Save this as 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>
Then your individual pages would be like this:
<?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");?>
这篇关于HTML模板 - PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!