html - 从子文件夹调用 header

标签 html css

我正在根文件夹中组织我的文件。基本问题是没有调用 CSS 和 JS。从“page-services-3.php”我必须调用标题。因为 php 站点位于子文件夹中,所以我尝试了以下内容:

<?php include $_SERVER['DOCUMENT_ROOT'] . '/resources/includes/header.php' ?>

<?php include $_SERVER['DOCUMENT_ROOT'] . '/resources/includes/footer.php' ?>

我尝试使用 CSS 的普通 href(如下图),我还在标题中的 CSS 文件前面设置了这个:

<link href="http://localhost:8888/Portfolio-Version-2//plugins/magnific-popup/magnific-popup.css" rel="stylesheet">

enter image description here

但我只是得到以下页面:

enter image description here

从子文件夹中调用 header 的正确语法是怎样的? $_SERVER['DOCUMENT_ROOT'] 在其他一些元素中使用完全相同的文件夹结构为我工作。

更新

回答后我尝试执行以下操作:

在我的 page-services.php 中,我尝试了以下操作:

<?php require"http://localhost:8888/'resources/includes/header.php'"; ?>

    <body class="no-trans    ">

<?php require"http://localhost:8888/'resources/includes/navbar.php'"; ?>

<?php require"http://localhost:8888/'resources/includes/banner.php'"; ?>

我试图像这样在 header.php 和 index.php 中设置基数:

<?php define("http://localhost:8888/",dirname(dirname($_SERVER['SERVER_NAME']))); ?>

这只会导致以下错误:

本地主机页面不工作

最佳答案

尝试在索引页中这样做 只需定义网站路径

define("SITE_URL",dirname(dirname($_SERVER['SERVER_NAME'])));

SITE_URL : 包含 'http://localhost:8888/' 比你可以调用服务器中的任何文件 你可以做的 php 文件

require"SITE_URL.'some_folder/some_file.php'";

或者你可以做的css文件

<link href="<?echo  SITE_URL.'/some_folder/some_file.css';?> " rel="stylesheet">

更多解释如何使用 php 路由器访问 php router

关于html - 从子文件夹调用 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40566244/

相关文章:

javascript - 如何将警报值添加到元素

html - 对齐按钮 - 图标与 html/css/bootstrap 3 中的按钮?

html - 使用CSS为每个打印页面添加边框?

html - 想在选择框中显示有限的数字

html - 在公共(public)网站上使用 schemeless 协议(protocol) URI 是 "safe"吗?例如//www.example.com/dir/file

php - 如何使用记录插入向导上传文件? php 的 Dreamweaver

javascript - 禁用 iOS flex 体滚动并保持 native 滚动工作

javascript - 如何保持动态大小、堆叠的 div 的相对位置/大小

html - 我怎样才能解决 Firefox 和 IE7 中明显的不一致问题?

javascript - 产品库 - 该网站如何为每种可能的组合生成图像