HTML模板 – php?

前端之家收集整理的这篇文章主要介绍了HTML模板 – php?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以,我正在建立一个关于第一次世界大战的网站作为学校作业,我希望它出现在每个文件中:
<!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> &bull;
    <a href="about.htm">About</a>
    </footer>
  </div>
</body>
</html>

我认为将所有这些复制粘贴到每个文档中都是一种愚蠢的做法,如果我只想更改一个单词或标记,那就费力地单独更改每个页面.有没有办法我可以把它放在template.htm(或类似的东西)中,并有PHP或javascript代码取此并插入< article>内所需的文件内的所有内容标签?我不知道很多PHP,所以这对你的大师来说可能是件小事,但我会很感激帮助.

解决方法

使用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>

将其保存为bottom.PHP

<aside>
</aside>
</section>
<footer style="font-weight: bold; letter-spacing: .1em">
<a href="citations.htm">Citations</a> &bull;
<a href="about.htm">About</a>
</footer>
</div>
</body>
</html>

然后您的个人页面将是这样的:

<?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");?>
原文链接:https://www.f2er.com/html/225273.html

猜你在找的HTML相关文章