检测正在使用哪个 WordPress 模板 [英] Detect which WordPress template is being used
本文介绍了检测正在使用哪个 WordPress 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 header.php 中,是否有某种方法可以检测和提醒当前页面显示的是哪个模板?例如,我尝试了类似的操作:
In header.php, is there some way to detect and alert which template is displaying the current page? For example, I attempted something like:
<script type="text/javascript">
alert("<?php echo is_page_template(); ?>");
</script>
我更喜欢不需要我明确说明和测试该警报中的每个文件名的答案.但是,即使我确实输入了模板文件的名称,它也会提示空白而不是 true 或 false.有什么想法吗?
I would prefer an answer that doesn't require me to explicitly state and test each filename in that alert. But, even when I did put in a template file's name, it alerted blank rather than true or false. Any ideas?
推荐答案
您可以执行以下操作:
You can do the following:
get_post_meta($post->ID,'_wp_page_template',true);
这篇关于检测正在使用哪个 WordPress 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文