Jas*_*son 6 wordpress wordpress-theming
假设我有一个WordPress安装,页面名为"关于".如果我去http://example.com/about,我从WordPress的模板层次结构页面知道我正在查看主题文件page.php.
我想知道是否有办法在页面某处显示该事实(用于主题调试)?就像我将调用什么函数(或代码)来显示当前用于呈现我正在查看的页面的PHP页面.
我可以做一些事情$_SERVER['PHP_SELF'],但我正在寻找一种方法,我不必编辑每个PHP文件.就像在调用页面时一样吐出它正在使用的文件列表.
可以将其打印在HTML源代码中,如下所示:
add_action( 'wp_head', 'so_9405896_show_template', 999 );
function so_9405896_show_template() {
global $template;
echo '
<!--
TEMPLATE = ' . basename($template) .'
-->
';
}
Run Code Online (Sandbox Code Playgroud)
或为了更容易可视化,可直接在内容中添加以下内容:
add_filter( 'the_content', 'so_9405896_the_content_filter', 20, 1 );
function so_9405896_the_content_filter( $content )
{
if( is_admin() || !current_user_can( 'administrator' ) )
return $content;
global $template;
$the_templ = '<strong style="background-color: #CCC;padding:10px">TEMPLATE = '
. basename( $template ) . '</strong><br />';
$content = sprintf( $the_templ . '%s', $content );
return $content;
}
Run Code Online (Sandbox Code Playgroud)
结果是:
| 归档时间: |
|
| 查看次数: |
1934 次 |
| 最近记录: |