我正在建立一个网站,基本上它包含7-8页。只是想知道如果我必须再次编写整个编码&再次...像NAVBAR,HEADER,FOOTER等东西?
如果我想进行一些更改,我需要做什么?我必须为每个页面手动编辑代码吗?
答案 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
希望这有帮助。