基本上,这在admin中不可用。您可以查看我的个人资料,转到我的github页面并获取"current admin info" plugin. 但这对你没有多大帮助。
这将显示模板名称:
get_page_template_slug( get_queried_object_id() );
在前端,您可以使用以下插件,该插件将显示该信息(来自另一个问题)。
<?php
/** Plugin Name: (#10537) »kaiser« Get Template file name */
if ( ! class_exists( \'wpse10537_template_name\' ) )
{
add_action( \'plugins_loaded\', array( \'wpse10537_template_name\', \'init\' ) );
class wpse10537_template_name
{
protected static $instance;
public $stack;
public static function init()
{
is_null( self :: $instance ) AND self :: $instance = new self;
return self :: $instance;
}
public function __construct()
{
if ( is_admin() )
return;
add_action( \'wp\', array( $this, \'is_parent_template\' ), 0 );
add_action( \'wp\', array( $this, \'get_template_file\' ) );
add_action( \'template_include\', array( $this, \'get_template_name\' ) );
add_action( \'wp_footer\', array( $this, \'get_template_name\' ), 100 );
}
public function get_template_name( $file )
{
if ( \'template_include\' === current_filter() )
{
$this->to_stack(
"Template file"
,basename( $file )
);
return $file;
}
// Return static var on echo call outside of filter
if (
current_user_can( \'manage_options\' )
AND defined( \'WP_DEBUG\' )
AND WP_DEBUG
)
{
return printf(
\'<div><p style="text-align:center;">%s</p></div>\'
,implode( " – ", $this->stack )
);
}
}
public function get_template_file()
{
if ( ! is_post_type_hierarchical( get_post_type() ) )
return;
$slug = get_page_template_slug( get_queried_object_id() );
if ( ! strstr( $slug, "/" ) )
return $this->to_stack( "Template", $slug );
// Subdirectory info
$this->to_stack(
"Subdirectory"
,strstr( $slug, "/", true )
);
$this->to_stack(
"Template (in subdirectory)"
,str_replace( "/", "", strstr( $slug, "/" ) )
);
}
public function is_parent_template()
{
if ( ! is_null( wp_get_theme()->parent ) )
return $this->to_stack( \'from parent theme\' );
$this->to_stack( \'from current/child theme\' );
}
public function to_stack( $part, $item = \'\' )
{
$this->stack[] = "{$part}: {$item}";
}
} // END Class wpse10537_template_name
} // endif;
如果所有这些都不能作为起点,那么请看看
all the related answers.