繁体   English   中英

PHP页眉和页脚

[英]PHP headers and footers

我想使用php incluse标记在我的网站上创建一致的页眉和页脚。 创建头文件时,我是否需要html和body标签,还是可以仅以div id =“ header” ....开头?

包含所有内容后,您应该担心的是网站标记的最终结果。

例:

header.php

<div id="header"></div>

footer.php

<div id="footer"></div>

index.php

<html>
<head></head>
<body>
    <?php include('header.php'); ?>
    <div id="content"></div>
    <?php include('footer.php'); ?>
</body>
</html>

为了获得正确的语义,请包含<html><body>标记,并确保在footer.php文件中将其关闭

您可以在这样的文件中包含一部分HTML。

<footer> This is my global footer! </footer>

然后在PHP中,您可以使用include()包含该html文件。 它将文件的内容呈现到包含它的输出中。

include 'globalFooter.html';

我需要html和body标签,还是可以仅从div开始?

你不可以。

您的问题尚不完全清楚,但是您似乎在询问是否需要在包含的文件中添加任何特殊标签。 简短的答案是“否” —将包含的文件逐字插入到包含文件中,因此它将包含呈现所需的标头(或页脚)所需的任何标签。

无论您做什么,结果都应该是有效的HTML。

因此,如果您的index.php<?php include "header.php" ?>开头,那么您的header.php文件应以<!DOCTYPE html><html>...开头。

是的你应该。 不过,最好在include中使用变量将诸如<title>类的内容设置为...

<?php 
$pagetitle="My page";
include('header.php');
?>
Content here
<?php include('footer.php'); ?>

header.php在哪里

<html>
<head>
<title><?php echo $pagetitle; ?></title>
<!-- your meta tags etc -->
</head>
<body>

和页脚是

<script>/* your javascript includes */</script>
</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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