Wordpress 页面模板是否正在检查包含的文件
我需要检查我的自定义页面模板是否为index-with-sidebar.php 我就是这样做的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<
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 )); ?>