简体   繁体   English

在Wordpress模板中包含PHP文件

[英]Including PHP file in Wordpress Template

As of right now I have this code in one of my templates on my Wordpress theme. 截至目前,我在Wordpress主题的模板之一中已包含此代码。

// blah blah

        <div class="content">

            <?php include_once( 'http://www.website.com/new/file.php?variable=1' ); ?>

        </div>

// blah blah

Now, it will load everything in this template except this php include! 现在,它将加载此模板中的所有内容,但此php include除外! It will load the sidebar which is included above the /* blah blah */ and it will load the footer, navigation, etc. 它将加载/ *等等* /上方的侧边栏,并将加载页脚,导航等。

When I Inspect Element on Google Chrome it shows this: 当我在Google Chrome浏览器中检查Element时,它显示如下:

<div class="content">

       (it's empty)

</div>

Please help me if you know what I'm doing wrong! 如果您知道我在做什么错,请帮助我! Thank you! 谢谢!

include and require don't take URLs. includerequire不要使用网址。 They take server filepaths. 他们采用服务器文件路径。 Try this: 尝试这个:

<?php include_once(ABSPATH.'/new/file.php'); ?>

EDIT: Forgot to mention that query strings cannot be included in filepaths. 编辑:忘记提及查询字符串不能包含在文件路径中。 If a query string is necessary for proper loading, consider loading the page with all necessary query variables in your current URL, loading the part using an iframe, or using file_get_contents() 如果需要正确输入查询字符串,请考虑使用当前URL中的所有必需查询变量来加载页面,使用iframe或使用file_get_contents()加载部分

Iframe: iframe:

<iframe src="http://www.website.com/new/file.php?variable=1"></iframe>

file_get_contents() file_get_contents()

<?php echo file_get_contents('http://www.website.com/new/file.php?variable=1'); ?>

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

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