gpt4 book ai didi

php - 如何在网站的每个页面上添加导航栏?

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:56 24 4
gpt4 key购买 nike

您好,我是创建网站的新手,最近一直在研究 HTMl 和 CSS。我创建了一个导航栏,想把它放在每个页面上。我以前调查过这个,但就是想不通。它只是不放在页面的导航栏中。

主页.html

                            <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php include 'navbar.php';?>
<div id="hbox1">
<h2>Random</h2>
<p>Is he staying arrival address earnest. To preference considered it themselves inquietude collecting estimating. View park for why gay knew face. Next than near to four so hand. Times so do he downs me would. Witty abode party her found quiet law. They door four bed fail now have. <a href="#">here.</a></p>
</div>
<div id="hbox2">
<h2>Random</h2>
<p>Is he staying arrival address earnest. To preference considered it themselves inquietude collecting estimating. View park for why gay knew face. Next than near to four so hand. Times so do he downs me would. Witty abode party her found quiet law. They door four bed fail now have. <a href="#">here.</a></p>
</div>
<div id="hbox3">
<h2>Random</h2>
<p>Is he staying arrival address earnest. To preference considered it themselves inquietude collecting estimating. View park for why gay knew face. Next than near to four so hand. Times so do he downs me would. Witty abode party her found quiet law. They door four bed fail now have. <a href="#">here!</a></p>
</div>
<div id="hbox4">
<h2>Random</h2>
<p>Is he staying arrival address earnest. To preference considered it themselves inquietude collecting estimating. View park for why gay knew face. Next than near to four so hand. Times so do he downs me would. Witty abode party her found quiet law. They door four bed fail now have. <a href="#">here.</a></p>
</div>
</body>
</html>

和 navbar.php

                            <h1>&nbsp&nbspMy Homepage</h1>
<ul id="nav">
<li><a href="#">Random</a></li>
<li><a href="#">Random</a></li>
<li><a href="#">Random</a></li>
<li><a href="#">Random</a></li>
</ul>

最佳答案

您的代码无法正常工作的原因是您尝试使用 .html 文档解析 PHP 代码。

要么指示 Apache 将 .html 文件视为 PHP,要么将 home.html 重命名为 home.php


.html 文件视为 PHP。

在服务器根目录的 .htaccess 中:

<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>

或单个文件名:

<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>

或多个文件名:

<FilesMatch "^(file_one|file_two|file_three)\.html$">
AddType application/x-httpd-php .html
</FilesMatch>

AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php .php .htm .html

对于 HostGator 托管的人:Source

AddHandler application/x-httpd-php5 .html .htm

如果您在本地使用 XAMPP 进行开发,则应该使用 AddHandler 而不是 AddType

AddHandler application/x-httpd-php .html .htm

关于php - 如何在网站的每个页面上添加导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29055252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com