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
Wordpress 页面模板是否正在检查包含的文件_Wordpress_Templates - Fatal编程技术网

Wordpress 页面模板是否正在检查包含的文件

Wordpress 页面模板是否正在检查包含的文件,wordpress,templates,Wordpress,Templates,我需要检查我的自定义页面模板是否为index-with-sidebar.php 我就是这样做的 function index_with_sidebar() { echo (is_page_template('index-with-sidebar.php')) ? 'col-md-6' : 'col-md-4'; } 在content.php中,我有 <div class="item <?php index_with_sidebar(); ?> ">item<

我需要检查我的自定义页面模板是否为index-with-sidebar.php

我就是这样做的

function index_with_sidebar() {
    echo (is_page_template('index-with-sidebar.php')) ? 'col-md-6' : 'col-md-4';
}
在content.php中,我有

<div class="item <?php index_with_sidebar(); ?> ">item</div>
循环中

<?php $e = has_post_format() ? 'content-'.get_post_format().'.php' : 'content.php'; ?>
<?php require(locate_template( $e )); ?>


我可以在content-X.php模板中使用$g变量:)

如果调用content.php中的函数,则页面模板不是index-with-sidebar.php,因此输出错误答案是正确的


要得到一个真实的结果,您可以使用sidebar.php调用索引中的函数。

是,同意!但是我需要以某种方式将结果传递给content.php,我不知道您的模板是如何构造的?是否从index-with-sidebar.php调用content.php?
<?php $g = index_with_sidebar(); ?>
<?php $e = has_post_format() ? 'content-'.get_post_format().'.php' : 'content.php'; ?>
<?php require(locate_template( $e )); ?>