Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php代码获取page.php_Php_Wordpress_Wordpress Theming - Fatal编程技术网

使用php代码获取page.php

使用php代码获取page.php,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我在wordpress工作 我看到在我的index.php中有一个名为的代码。我明白了,它很简单。此代码将拉取footer.php 在我看来,get\u footer()内置于wordpress中,它可以提取任何名为footer.php的内容 我已经创建了自己的页面,名为page.php 我希望能够“获取”这个页面,并在我的php代码支持的“边栏小部件”中显示 我已尝试粘贴此代码,我更确信它是错误的: <?php echo file_get_contents("side.php"); ?&

我在wordpress工作

我看到在我的index.php中有一个名为
的代码。我明白了,它很简单。此代码将拉取
footer.php

在我看来,
get\u footer()
内置于wordpress中,它可以提取任何名为
footer.php
的内容

我已经创建了自己的页面,名为
page.php

我希望能够“获取”这个页面,并在我的php代码支持的“边栏小部件”中显示

我已尝试粘贴此代码,我更确信它是错误的:

<?php
echo file_get_contents("side.php");
?>

如果希望显示名为
page.php
的自定义页面,我需要什么代码?

请尝试以下操作

include ('side.php');


您也可以使用include_once/require_once

page.php是wordpress的一个特殊页面。看这个图表。

wordpress的方法是创建自己的模板。
在php页面中添加此代码

<?php include_once('filename.php'); ?>

请使用require\u一次或包含在php文件中,如下所示

require_once('side.php');

试试这个

require( dirname( __FILE__ ) . '/page.php' ); require(dirname(_文件)'/page.php');
如果您的页面与父页面处于同一级别。

WordPress加载模板文件的方法是:

请注意,
page.php
是WordPress主题中的一个特殊文件名,如果显示一个页面,该文件将作为模板加载。如果要防止出现这种情况,应为文件指定不同的名称

详情见上文所述

编辑:


在重新阅读您的问题后:如果您的
page.php
不是来自模板,而是在作为边栏小部件开发的插件的文件夹中,那么前面提到的
include('page.php')将是一种选择。

有很多选项可供选择:

您可以使用
get\u template\u part()

:WordPress现在提供了一个函数,
get\u template\u part(),
这是本机API的一部分,专门用于重用
代码的节或模板(页眉、页脚和
(侧边栏)通过您的主题

另一种解决方案是
require\u once()
include\u once()
。 但是,如果我比较这两个函数,对于较小的应用程序,
include_once()
require_once()
更快


为了更好地理解
require
include
,您可以阅读这篇文章。

尝试
include'side.php'
使用此选项另一个注意事项:
文件获取内容
将下载文件的HTML内容,如web浏览器中所示。这不是您想要的,您想要包括或需要您的文件。
include ('side.php');
require( dirname( __FILE__ ) . '/page.php' );
get_template_part( 'page' );
// loads page.php from the theme directory.