很简单,您将创建没有导航的普通页面,以及它们的普通链接,然后您将创建导航以将其添加为组件。
导航.php
<nav>
<ul>
...
</ul>
</nav>
index.php
<?php include_once "nav.php"; ?>
<p>index</p>
contacts.php
<?php include_once "contacts.php"; ?>
<p>contacts</p>
编辑
如果您包含的文件太多,并且您想要一个简短的包含,您可以通过包含您想要包含的所有文件然后在任何您想要的地方包含该文件来做到这一点,最好将它们添加到页面的单独文件夹中像组件或包含,像
包含/css_files.php
<link rel="stylesheet" href="...">
<link rel="stylesheet" href="...">
<link rel="stylesheet" href="...">
<link rel="stylesheet" href="...">
<link rel="stylesheet" href="...">
<link rel="stylesheet" href="...">
包含/metas.php
<meta bla="" bla="" bla=""\>
<meta bla="" bla="" bla=""\>
<meta bla="" bla="" bla=""\>
<meta bla="" bla="" bla=""\>
包含/seo.php
<meta keywords="StackOverflow, HTML">
<meta keywords="StackOverflow, HTML">
<meta keywords="StackOverflow, HTML">
对于includes.php 文件,你必须选择:
- 就是把include文件和pages放在同一个目录下,会是这样的
包括.php
<?php
include "includes/seo.php";
include "includes/metas.php";
include "includes/css_files.php";
- 您可以将它与其他包含在同一目录中,但不要删除包含之前的
includes/。
包括.php
include "includes/seo.php";
include "includes/metas.php";
include "includes/css_files.php";
然后页面会像
<head><?php include "includes.php"; ?></head>
<p>...</p>
因为包含在 PHP 中包含了代码 COPY&PASTE,所以你会像在页面中编写它一样对待它。例如,如果你没有在文件名前写includes/,index.php 会是这样的:
<head>
<?php
include "seo.php";
include "metas.php";
include "css_files.php";
?>
</head>
index lorem ipsum
它不会包含它,因此包含也不会只获取文件并将其按原样放置在文件中而不更改任何内容