简体   繁体   中英

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 .

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.

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

Well a shortcut, you could do this.

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.

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 :

header.php

<div class="header">
   <p>this is a header</p>
</div>

index.php

<?php require_once 'header.php'; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM