我可以告诉引用包含的PHP文件的位置吗?

时间:2017-01-31 12:06:32

标签: php wordpress

Wordpress有许多有用的功能可以找出你正在查看的当前页面是什么,但是有没有办法找出哪个模板文件已经包含来自哪个

例如:

在我的主题中,我正在使用多个页面模板。我有一个PHP文件,其中包含我想要在网站的各个位置显示的块,包括不同的页面模板和侧边栏

我需要根据我所在的页面对wpdb->get_results进行稍微不同的调用,但是当这个PHP文件包含在sidebar.php中时,我还想提供不同的查询。

到目前为止,侧栏中的块仅遵循以下语句的else部分,并且使用get_template_part('sidebar.php')不起作用。

if( is_page_template('template-procedure.php') ) {
    $beforeAfters = $wpdb->get_results('SELECT * FROM wp_before_after WHERE procedureID = '.$post->ID.' AND procedure_display = 1 ORDER BY ID DESC');
} elseif( is_page_template('template-patient-story.php') ) {
    $beforeAfters = $wpdb->get_results('SELECT * FROM wp_before_after WHERE patientID = '.$post->ID.' AND patient_display = 1 ORDER BY set_order ASC');
} elseif( is_page_template('sidebar.php') ) {
    $beforeAfters = $wpdb->get_results('SELECT * FROM wp_before_after WHERE procedureID = 238 AND sidebar_display = 1 ORDER BY RAND()');
}

如何定位侧边栏文件,同时还使用页面模板?

0 个答案:

没有答案