简体   繁体   English

为什么PHP包含元素不会显示在包含侧边栏中?

[英]Why PHP included element won't show in included sidebar?

I have site where I have global sidebar included on all pages with PHP. 我有一个站点,在所有PHP页面上都包含全局侧边栏。 I'm trying to include contact information in that included sidebar and also include same contact information in main content of some pages. 我试图在包含的侧边栏中包含联系信息,并且在某些页面的主要内容中也包含相同的联系信息。

Page construction is as followed: 页面构造如下:

Main content (in public_html) including contact information: include('contact.php'); 主要内容(在public_html中)包括联系信息:include('contact.php');
contact.php is located in public_html contact.php位于public_html中

Included sidebar (from public_html/parts include('parts/sidebar.php')) including same contact information: include('../contact.php'); 包含的侧边栏(来自public_html / parts include('parts / sidebar.php')),包括相同的联系信息:include('../ contact.php');

My problem is that contact information shows up only in main content and not in sidebar. 我的问题是联系信息仅显示在主要内容中,而不显示在侧边栏中。

you have to use dirname function of php 您必须使用php的dirname函数

for example 例如

file of sidebar 边栏文件

include dirname(__FILE__).'/contact.php';

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

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