在许多练习网站之后,我终于创建了一个发布的网站。问题是,如果我需要更改设计,即在每个页面中将要更改的文本之前和之后(编码),那么我将不得不在每个文件中更改它。任何人都可以告诉我,我可以通过哪种方式更改文本下方和上方的代码。请帮助我的任何标签,代码,软件等。 谢谢
答案 0 :(得分:3)
您可以使用PHP来包含页眉和页脚。
例如,您将所有标题和菜单放在“header.html”中,并将所有页脚,copyright,...放在“footer.html”中。
,创建一个index.php。在这个页面中,您可以这样写:
<?php include 'header.html'; ?>
<p>body</p>
<?php include 'footer.html'; ?>
答案 1 :(得分:2)
很容易;分离您的模板文件。
// header.php
<html>
<head>
<title>My beautiful website</title>
<script src="script.js"></script>
....
</head>
<body>
// footer.php
</body>
</html>
// content.php
<?php include('header.php'); ?>
<h1>Welcome on my website</h1>
<p>Lorem ipsum</p>
<?php include('footer.php'); ?>
现在,如果您想要更改内容,请更改header.php,每个内容页面上都会显示更改。
请注意;你也可以扭转局面(包括'基础模板文件中的'content.php')
答案 2 :(得分:1)
将您的代码划分为3个.php
个文件
header.php
- 您内容之上的所有内容content.php
- 您的内容footer.php
- 您内容下的所有内容然后在您的index.php
文件(以及所有其他文件)中包含它们,例如:
<?php
$meta = 'This page meta info';
include('header.php');
include('content.php');
include('footer.php');
?>
<强>的header.php 强>
<html>
<meta="<?php echo $meta; ?>" />
...
答案 3 :(得分:0)
你可以使用包含
<?php include('templates/global_header.tpl') ?>
要做到这一点,你需要你的主页有扩展名.php而不是html。