[英]How to dynamic insert the header and footer of mainpage.html on other pages?
我查找了許多示例,了解如何從一個頁面向其他頁面動態顯示相同的 header 和頁腳,而無需重復相同的 html 代碼和樣式。
不幸的是,我找不到這樣做的明確示例,我已經看到可以使用 PHP,但我還沒有找到任何實際示例。
如果有人能給我一個例子或一篇文章,我將不勝感激。
您可以對 php 使用 include(),一頁中有 header,另一頁中有頁腳。 header.php 類似的東西
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
</head>
<body>
頁腳.php
<footer>
<p>Author: Hege Refsnes</p>
<p><a href="mailto:hege@example.com">hege@example.com</a></p>
</footer>
</body>
</html>
每隔一頁
<?php include 'header.php';?>
<div>
your content...
</div>
<?php include 'footer.php';?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.