[英]How to edit, for example, the header of one HTML file and make it do the same to all other pages, without changing all the pages manually?
More in-depth; 更深入; for example, about any website at the moment has a navigation bar. 例如,目前任何网站都具有导航栏。 With hundreds of pages, as an example, how would you edit it accordingly on one page - which will modify the navigation bar on all other pages you've got without changing each page its navbar manually? 以数百个页面为例,如何在一个页面上进行相应的编辑-这将修改您拥有的所有其他页面上的导航栏,而无需手动更改每个页面的导航栏?
All you need to do is to create a common have header file and include in every page. 您需要做的就是创建一个通用的头文件,并将其包含在每个页面中。
This can be done with PHP s include
or require
. 这可以通过PHP的include
或require
来完成。
well, it depends: because this task is normally performed by the server , each server platform manage this problem in a different way. 好吧,这取决于:因为此任务通常由服务器执行,所以每个服务器平台都以不同的方式管理此问题。 for instance : ASP.NET applications using a MasterPage mechanism in order to define a main template for the entire site, with "frames" that changes from page to page. 例如 :使用MasterPage机制的ASP.NET应用程序,以便为整个站点定义一个主模板,其“框架”在页面之间变化。
on the client side this is normally performed by iframe tags... so it really depends which platform are you using and if your stratedgey focus on the server side or on the client side 在客户端,这通常是由iframe广告代码执行的...因此,这实际上取决于您使用的平台以及您的策略是集中在服务器端还是客户端
Well a shortcut, you could do this. 好快捷方式,您可以执行此操作。
Index.php Index.php
///header code
<?
if(empty($pg))
$var = "p/home.php";
if(empty($_SERVER["QUERY_STRING"])) {
include($var);
} else {
include("p/$pg.php");
}
?>
////footer code
Now just link you links to "?pg=NAME_OF_THE_PAGE" without the ".php" and you will have a standard index that you can chage menu, header and footer that will change for all pages. 现在,只需将您的链接链接到没有“ .php”的“?pg = NAME_OF_THE_PAGE”,您将拥有一个标准索引,您可以更改菜单,页眉和页脚,所有页面都将更改。
Note: the pages that you will create, just put the content, with no header or footer. 注意:您将创建的页面仅放置内容,没有页眉或页脚。
Hope it helps. 希望能帮助到你。
As programming student said, use include
or require
: 正如编程学生所说,使用include
或require
:
header.php header.php
<div class="header">
<p>this is a header</p>
</div>
index.php index.php
<?php require_once 'header.php'; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.