如何在创建网站时使用布局/模板?

时间:2015-03-02 09:37:24

标签: html

我正在建立一个网站,基本上它包含7-8页。只是想知道如果我必须再次编写整个编码&再次...像NAVBAR,HEADER,FOOTER等东西?

如果我想进行一些更改,我需要做什么?我必须为每个页面手动编辑代码吗?

1 个答案:

答案 0 :(得分:2)

也许你应该考虑使用PHP include语句来避免不得不通过多个文件重复代码。

以下是一个例子:

的header.php

<header>
    <!-- All the code for your header -->
<header>

myWebpage1.php

<!-- All the head stuff, title, meta, styles, etc. -->
<body>
<?php
    include "header.php";
?>
<h1>My webpage 1</h1>
<!-- On and on... -->

myWebpage2.php

<!-- All the head stuff, title, meta, styles, etc. -->
<body>
<?php
    include "header.php";
?>
<h1>My webpage 2</h1>
<!-- On and on... -->

您可以在所有网页文件中使用include语句,只要它们是PHP文件。

更多信息位于:http://php.net/manual/en/function.include.php

希望这有帮助。