获取当前模板文件的名称
-
-
@chodorowicz-尽管我将把"functions.php"的选择称为错误仅差一个步骤,但我完全同意您的前提.更糟糕的是,我扫描了WordPress核心代码,发现了大约5个可能存在钩子的地方,可以让您处理此问题,但我没有发现.我建议在http://core.trac.wordpress.org上发布票证.@chodorowicz - While I will stop one step short of calling the selection of `functions.php` as a bug, I will agree completely with your premise. To make matters worse I scanned the WordPress core code and found about 5 places where there could have been a hook to allow you to handle this issue yet I found none. I'd suggest posting a ticket on http://core.trac.wordpress.org.
- 2
- 2011-02-26
- MikeSchinkel
-
@MikeSchinkel-感谢您的评论,但是t31os建议的`template_include`钩子不能解决问题吗?也许我误会了你.@MikeSchinkel - thanks for comment, but doesn't `template_include` hook, which t31os suggested, solve the issue? Or maybe I've misunderstood you.
- 0
- 2011-02-27
- chodorowicz
-
@chodorowicz-您现在让我很困惑.@t31os给出的答案解决了一个与我理解的基于您的问题以及您对其他答案的后续评论所提出的问题截然不同的问题.但是,如果@t31os的答案解决了您的实际需求,那么我的困惑就不重要了,因为您的问题已得到回答.@chodorowicz - You now have me very confused. The answer @t31os gave solves a problem that is very different from the one that I understood you were asking based on your question and your follow up comments to other's answers. But if @t31os' answer solved your actual need, then my confusion here is unimportant as your question has been answered.
- 0
- 2011-02-27
- MikeSchinkel
-
是的,实际需要是显示当前使用的主题文件的名称,我发布的代码有缺陷(可以通过将功能移出主主题文件夹来解决),但是@t31os的解决方案更简洁,满足了需求,但是,如果我对您的理解正确,那么实际的问题(WP不应尝试将"functions.php"作为页面模板文件读取)仍然存在.我会尝试将其发布在trac上,尚未完成.问候!Yes, the actual need was to display the name of the currently used theme file, the code I posted had a flaw (which can be solved by moving the function out of the main theme folder), but @t31os' solution is much cleaner and fulfills the need, but, if I understand you correctly, the real problem (WP shouldn't try to read `functions.php` as page template file) still persists. I'll try to post it on trac, haven't done it yet. Greetings!
- 0
- 2011-02-27
- chodorowicz
-
@MikeSchinkel-它已经有一个补丁:) http://core.trac.wordpress.org/ticket/16689@MikeSchinkel - it already has a patch :) http://core.trac.wordpress.org/ticket/16689
- 1
- 2011-02-28
- chodorowicz
-
@chodorowicz-是的,我的评论是针对真正的问题的,返回的是防止WP尝试读取`functions.php`和/或允许您编写钩子以进行更改.很高兴看到您找到了补丁,而不是重复了;很难找到那些现有的票.@chodorowicz - Yes, my comment was addressing the real problem, keeping WP from trying to read `functions.php` and/or allowing you to write a hook to change was is returned. Glad to see you found a patch rather than duplicate it; it's so hard to find those existing tickets.
- 0
- 2011-02-28
- MikeSchinkel
-
^即.您从我的答案中获取了代码,并将其包装到插件中.而且您所做的所有事情都没有对来源进行任何贡献,无论是我本人还是WP stackexchange ...都不错...:/^ ie. you took the code from my answer and wrapped it into a plugin. And you did all that without providing any credit to the origin, neither myself or the WP stackexchange... nice... :/
- 4
- 2014-03-30
- t31os
-
9 个回答
- 投票数
-
- 2011-04-09
显然这足够了:
add_action('wp_head', 'show_template'); function show_template() { global $template; echo basename($template); }
或直接在模板中使用它(我倾向于在HTML注释中的footer.php中回显)
<?php global $template; echo basename($template); ?>
apparently this is enough:
add_action('wp_head', 'show_template'); function show_template() { global $template; echo basename($template); }
or just use it directly in template (I tend to echo in footer.php in HTML comment)
<?php global $template; echo basename($template); ?>
-
众所周知,那将无法与get-template-part一起使用,例如,它仅显示single.php,而不显示其中的文件.That won't work with get-template-part just so you know, it only shows single.php (for example) and not the file it is in.
- 1
- 2012-09-25
- m-torin
-
对,是真的.要获得包含文件的名称,您可能需要使用类似"echo __FILE__;"的名称.Yes, it's true. To get the name of included file you'd probably need to use something like this `echo __FILE__;`
- 0
- 2012-10-05
- chodorowicz
-
这很好,例如,在您修改默认模板而不将其分配给后台的帖子的情况下.例如,使用自定义路由和template_include过滤器.谢谢.this is fine, for example in cases when you modify the default template without assigning it to a post in backoffice. For example using custom routes and the template_include filter. Thank you.
- 0
- 2016-09-15
- Luca Reghellin
-
我如何在一个循环中做到这一点?我正在尝试将URL输出到每个模板文件的一页.How could I do this within a loop? I'm trying to output the URL to one page of each template file.
- 0
- 2017-02-28
- JacobTheDev
-
@JacobTheDev可能会使用`echo __FILE__`-因为这不起作用,它仅显示主要的初始模板@JacobTheDev maybe using `echo __FILE__` - because this won't work, it displays only main, initial template
- 0
- 2017-03-07
- chodorowicz
-
- 2011-02-27
您可以在
template_include
过滤器中设置一个全局变量,然后再检查该全局变量以查看其中包含了哪个模板.您自然不希望文件包含完整的路径,因此我建议使用PHP的
basename
函数将其截断为文件名.示例代码:
有两个功能,一个用于设置全局,一个用于调用全局.add_filter( 'template_include', 'var_template_include', 1000 ); function var_template_include( $t ){ $GLOBALS['current_theme_template'] = basename($t); return $t; } function get_current_template( $echo = false ) { if( !isset( $GLOBALS['current_theme_template'] ) ) return false; if( $echo ) echo $GLOBALS['current_theme_template']; else return $GLOBALS['current_theme_template']; }
然后您可以在主题文件中的任何需要的地方调用
get_current_template
,请注意,这自然需要在template_include
操作触发后发生(您不需要如果调用是在模板文件中进行的,则不必为此担心.对于页面模板,有
is_page_template()
,请记住,这仅在页面模板的情况下才有用(远远少于 catch all 功能).以上使用或引用的功能的信息:
You could set a global variable during the
template_include
filter and then later check that global vairable to see which template has been included.You naturally wouldn't want the complete path along with the file, so i'd recommend truncating down to the filename using PHP's
basename
function.Example code:
Two functions, one to set the global, one to call upon it.add_filter( 'template_include', 'var_template_include', 1000 ); function var_template_include( $t ){ $GLOBALS['current_theme_template'] = basename($t); return $t; } function get_current_template( $echo = false ) { if( !isset( $GLOBALS['current_theme_template'] ) ) return false; if( $echo ) echo $GLOBALS['current_theme_template']; else return $GLOBALS['current_theme_template']; }
You can then call upon
get_current_template
wherever you need it in the theme files, noting this naturally needs to occur after thetemplate_include
action has fired(you won't need to worry about this if the call is made inside a template file).For page templates there is
is_page_template()
, bearing in mind that will only help in the case of page templates(a far less catch all function).Information on functions used or referenced above:
-
- 2013-03-01
在get_template_part()等本机WP函数之间,PHP的本机包含最可靠的查看主题文件使用的方法,即获取列出所有包含的文件,并过滤掉不属于主题的内容(或使用父级和子级组合时的主题):
$included_files = get_included_files(); $stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() ); $template_dir = str_replace( '\\', '/', get_template_directory() ); foreach ( $included_files as $key => $path ) { $path = str_replace( '\\', '/', $path ); if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir ) ) unset( $included_files[$key] ); } var_dump( $included_files );
Between native WP functions like get_template_part() and PHP's native includes the most reliable way to see theme's files used is to fetch list of all included files and filter out whatever doesn't belong to theme (or themes when parent and child combination is used):
$included_files = get_included_files(); $stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() ); $template_dir = str_replace( '\\', '/', get_template_directory() ); foreach ( $included_files as $key => $path ) { $path = str_replace( '\\', '/', $path ); if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir ) ) unset( $included_files[$key] ); } var_dump( $included_files );
-
- 2012-09-08
这里的其他答案的补充(更甜蜜的代码).
模板名称
要仅获取当前的页面模板名称,请使用以下行.
is_page() AND print get_page_template_slug( get_queried_object_id() );
文件名
当您只想回显当前模板文件名时,请执行以下操作
编辑:这是包装在类中的新版本插件.它在页面最底部的关闭钩子中显示当前模板文件名以及模板层次结构文件名.
该插件告诉您的内容:
- 模板是子主题/当前主题的父模板吗?
- 模板是否从子文件夹提供?如果是:告诉您名字
- 模板文件名.
只需将以下代码复制到文件中,并将其命名为
wpse10537_template_info.php
,将其上传到您的插件目录中并激活它即可.<?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( 'shutdown', array( $this, 'get_template_name' ) ); } 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 print 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 ); $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;
此插件也可以作为MU-Plugin运行.
然后,您可以随时在任意点(例如主题模板)调用
wpse10537_get_template_name()
.这样可以避免混乱的全局名称空间.An addition (more sweet code) to other answers here.
Template Name
To just get the current page template name, use the following line.
is_page() AND print get_page_template_slug( get_queried_object_id() );
File Name
When you just want to echo the current template file name, go with the following
Edit: Here's the new version of the plugin wrapped up in a class. It shows both the current template file name, as well as the template hierarchy file name in the shutdown hook at the most bottom of the page.
What the plugin tells you:
- Is the template from the parent of child/current theme?
- Is the template served from a subfolder? If yes: Tells you the name
- The template file name.
Just copy the following code into a file and name it
wpse10537_template_info.php
, upload it to your plugins directory and activate it.<?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( 'shutdown', array( $this, 'get_template_name' ) ); } 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 print 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 ); $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;
This plugin can run as MU-Plugin too.
You can then simply call
wpse10537_get_template_name()
at any point (in for example a theme template). This avoids cluttering the global namespace.-
`template_redirect`没有传递任何东西,我认为您对`template_include`感到困惑.另外我会检查是否在过滤器内部,而不是是否填充了静态var.如果某些代码决定运行钩子额外的时间,则可能会破坏事情.`template_redirect` is not passing anything, I think you are confusing with `template_include`. Also I'd check if inside the filter instead of if static var filled. If some code decides to run hook additional time it can wreck things.
- 1
- 2012-09-15
- Rarst
-
@Rarst完成/已修复.感谢您的提示并指出过滤器名称.@Rarst Done/Fixed. Thanks for the hint and pointing out the filter name.
- 0
- 2012-09-15
- kaiser
-
- 2011-02-26
模板名称存储在postmeta表中,因此您所需要做的就是将其放在循环中的某个位置:
$template = get_post_meta( $post->ID, '_wp_page_template', true ); echo "Template: " . $template;
The template name is stored in the postmeta table, so all you need to do is put this somewhere in your loop:
$template = get_post_meta( $post->ID, '_wp_page_template', true ); echo "Template: " . $template;
-
是的,我知道这一点,但是问题在于它仅在页面具有设置的模板时才有效.关于我发布的代码,最酷的地方是它会告诉您当前页面是使用的是Front-page.php,index.php,single.php,page.php还是任何其他文件.您的代码仅显示具有自定义页面模板的页面的模板名称.Yes, I know about this, but the problem is that it works only when a page has a set template. The cool thing about the code I posted is that it will tell you if current page is using `front-page.php`, `index.php`, `single.php`, `page.php` or any other file. Your code displays template name only for pages with custom page template.
- 2
- 2011-02-26
- chodorowicz
-
啊,对不起-我对您的问题的误解.ah, sorry - my misunderstanding of your question.
- 0
- 2011-02-26
- Simon Blackbourn
-
@SimonBlackbourn这对我的要求有所帮助.谢谢.@SimonBlackbourn It's help for my requirement. Thanks.
- 0
- 2013-10-08
- KarSho
-
- 2013-05-01
这不能解决所有OP的问题,但是下面的代码肯定比正则表达式和解析模板文件本身更优雅.
如果您正在使用页面模板的页面上,并且想要获取页面模板的名称(即,您在模板PHP文件顶部的注释中定义的可读名称),您可以使用这个小块:
if ( is_page() && $current_template = get_page_template_slug( get_queried_object_id() ) ){ $templates = wp_get_theme()->get_page_templates(); $template_name = $templates[$current_template]; }
我想获取模板名称,因为我真的讨厌使用模板时内置的WordPress
body_class
函数创建的愚蠢的长屁股类名.幸运的是,该函数的末尾有一个过滤器挂钩,您也可以附加自己的类名.这是我的过滤器.希望有人觉得它有用:add_filter( 'body_class', 'gs_body_classes', 10, 2 ); function gs_body_classes( $classes, $class ){ if ( is_page() && $current_template = get_page_template_slug( get_queried_object_id() ) ){ $templates = wp_get_theme()->get_page_templates(); $template_name = str_replace( " ", "-", strtolower( $templates[$current_template] ) ); $classes[] = $template_name; } return $classes; }
此过滤器将采用您为页面模板命名的任何内容,用破折号代替空格,并将所有内容都转换为小写,使其看起来像所有其他WordPress类.
This doesn't address all of the OP's question, but the code below is certainly more elegant than regular expressions and parsing the template file itself.
If you're on a Page that is using a Page Template, and you want to get the page template's Name (ie: the human-readable name that you defined in the comments at the top of your template PHP file), you can use this little nugget:
if ( is_page() && $current_template = get_page_template_slug( get_queried_object_id() ) ){ $templates = wp_get_theme()->get_page_templates(); $template_name = $templates[$current_template]; }
I wanted to get the template name because I was really sick of the silly-long-ass class names that the built-in WordPress
body_class
function creates when you're using a template. Luckily there's a filter hook at the very end of that function to let you append your own class names as well. Here's my filter. Hope someone finds it useful:add_filter( 'body_class', 'gs_body_classes', 10, 2 ); function gs_body_classes( $classes, $class ){ if ( is_page() && $current_template = get_page_template_slug( get_queried_object_id() ) ){ $templates = wp_get_theme()->get_page_templates(); $template_name = str_replace( " ", "-", strtolower( $templates[$current_template] ) ); $classes[] = $template_name; } return $classes; }
This filter will take whatever you named your page template, replace spaces with dashes and make everything lower case so it looks like all the other WordPress classes.
-
- 2011-02-26
preg_match_all
行存在问题.尝试以下方法:preg_match_all("/Template Name:(.*)\n/siU",$template_contents,$template_name);
此外,您可以使用
if (!is_admin()) { .... }
仅在前端上运行事物.There's an issue with the
preg_match_all
line. Try this instead:preg_match_all("/Template Name:(.*)\n/siU",$template_contents,$template_name);
Also, you can use
if (!is_admin()) { .... }
to run things on the frontend only.-
感谢您的建议,他们不能解决问题,但可以引导我进入解决方案.事实证明,WP在生成模板列表的同时,甚至正在寻找`functions.php`来查找`"/Template Name:(.*)\n/siU"`,因此将`functions.php`视为模板文件..我认为这是WP错误,甚至不应该查看此文件.解决方案:将文件移到子目录中.Thanks for suggestion, they don't solve the problem, but they kinda directed me into solutions. It turns out that WP, while generating templates list, is looking even into `functions.php` finds the `"/Template Name:(.*)\n/siU"` and thus treats the `functions.php` as template file. I think this is WP bug, it shouldn't even look at this file. The solution: move the file into subdirectory.
- 0
- 2011-02-26
- chodorowicz
-
@chodorowicz:这不是WP中的错误,而是功能中的错误.@chodorowicz: That's not a bug in WP, it's a bug in your function.
- 0
- 2011-02-26
- wyrfel
-
因此,基本上WP禁止您将字符串" Template Name:"(即使在注释中)放在`functions.php`文件中.就我个人而言,这是一个错误(虽然很小,但无论如何),但我认为这取决于讨论.我认为您不能说该函数本身是错误的.So basically WP forbids you to put string "Template Name:" (even in comment) in `functions.php` file. For me, personally, that's a bug, (small, but anyway) but that's the up to discussion, I suppose. I think you cannot say that the function itself is buggy.
- 0
- 2011-02-26
- chodorowicz
-
WP不禁止您做任何事情.但是WP也不能保证您可以遍历debug_backtrace()来找出正在使用的模板文件.仅仅因为您在WP支持论坛上找到了它,并不意味着它是官方支持的代码.如您所见,您的函数显式排除了footer.php.您也可以添加另一个排除function.php的条件.顺便说一句:您的函数不会在每个文件中查找"模板名称",您的循环早已结束.WP doesn't forbid you to do anything. But WP also doesn't promise you that you can loop over a debug_backtrace() to find out what template file you're using. Just because you found it on a WP support forum doesn't mean it's officially supported code. As you may see, your function explicitly expludes footer.php. You may as well add another condition that excludes functions.php. BTW: your function doesn't look for `Template Name` within each of the files, your loop has ended long before that.
- 0
- 2011-02-27
- wyrfel
-
问题不在于`debug_backtrace()`-我可以删除所有代码,而只保留`preg_match_all("/Template Name ...",甚至只是`//Template Name:`,然后WP对待函数.php`作为模板文件,但是感谢您的评论-这是一个独特的问题,正如您所说,不公平地说它是一个bugt31os解决方案很干净,可以解决整个问题.The problem wasn't with `debug_backtrace()` - I can remove all the code and just leave `preg_match_all("/Template Name...`, or even just `// Template Name:` and WP treats then `functions.php` as template file, but thanks for comments - this is such a unique problem that, as you say, it's not fair to say it's a bug. t31os solution is clean and solves the whole issue. Greets.
- 0
- 2011-02-27
- chodorowicz
-
- 2017-09-15
播放:
echo '<ul><li>'.implode('</li><li>', str_replace(str_replace('\\', '/', ABSPATH).'wp-content/', '', array_slice(str_replace('\\', '/', get_included_files()), (array_search(str_replace('\\', '/', ABSPATH).'wp-includes/template-loader.php', str_replace('\\', '/', get_included_files())) + 1)))).'</li></ul>';
写在:
如果
admin-bar stuff
路径显示在顶部或任何其他文件中,请将此代码行中的文件名template-loader.php
更改为:您需要使用的filname.如果您需要在管理栏中进行此操作,请使用正确的优先级(最早)确保此列表末尾没有输入文件.例如:
add_action('admin_bar_menu', 'my_adminbar_template_monitor', -5);
优先级
-5
确保先加载.关键是在正确的时间渲染该行.它不返回"当前"模板文件,而是返回当前用于页面加载的所有当前文件. 也许从这个想法中运用了一些逻辑.
get_included_files()
" last"键是最后注册的包含文件,可能是页脚小部件中使用的最后一个模板文件/-部件.可能是,cos多个包含的文件不会在get_included_files()中重新注册/填充.否则,意图必须明确,才能破解该问题. 在包含文件之前,包含文件无法报告自己是否包含文件.然后可能会迟到使用该方案.
您想要的大部分"时间":
$template = get_current_loaded_template(); if($template == 'single-product.php') add_filter('the_title' .... if($template == 'format-gallery.php') add_action('post_thumbnail' ....
但这是不可能的,如果模板是在
.get_template_part
的Wordpress核心方法之外加载的.重新设计您的需求!也许loop_start()
,in_the_loop()
和add_action('the_post')
具有您想要的解决方案,可以根据模板更改数据为循环中的每个条目加载Play along with:
echo '<ul><li>'.implode('</li><li>', str_replace(str_replace('\\', '/', ABSPATH).'wp-content/', '', array_slice(str_replace('\\', '/', get_included_files()), (array_search(str_replace('\\', '/', ABSPATH).'wp-includes/template-loader.php', str_replace('\\', '/', get_included_files())) + 1)))).'</li></ul>';
Written at:
How do you find out which template page is serving the current page?
if
admin-bar stuff
path is showing at the top, or any other file, change the filenametemplate-loader.php
in this line of code to: whatever filname you need to break from.if you need this in the admin bar, use the right priotity (earliest) to make shure no files are entered at the end of this list. For example:
add_action('admin_bar_menu', 'my_adminbar_template_monitor', -5);
priority
-5
make shure it loads first. The key is to render this line at the right moment.It does not returning the "current" template-file, but all the current in use for the current page-load. Maybe "cut out" with some logic from that idea.
The
get_included_files()
"last" key is the last registered included file, propably the last template-file/ -part used in the footer by sidebar widget or something. Propably, cos mutiple included files does not re-register/ populates again in get_included_files().Otherwise, the intension must be clear to hack this problem. There is no way for a included file to report itself as included, until it has been included. Then its propably to late to use the scenario.
Most of the "time" you would like:
$template = get_current_loaded_template(); if($template == 'single-product.php') add_filter('the_title' .... if($template == 'format-gallery.php') add_action('post_thumbnail' ....
But thats not possible if the template is loaded outside Wordpress core method of
get_template_part
. Re-design your needs instead! Maybeloop_start()
,in_the_loop()
andadd_action('the_post')
has the solution you want, to alter data depending of template thats gonna load for each entry within a loop. -
我发现它可以显示模板中使用的文件的当前名称:
来源:获取页面模板的名称页面
它工作得很好,除了在后端的模板选择框中,我得到了这个丑陋的额外条目:
有人知道如何解决吗?我什至不知道为什么在后端调用此函数.是否有像
is_frontend()
这样的条件函数-也许这可以解决问题?