
如何编辑WordPress代码 – HTML、CSS、PHP
get_tag_template ( No parameters )
get_tag_template: 这个函数检索到标签存档模板文件的路径。它不接受任何参数,并以字符串形式返回模板文件的路径。
在当前或父模板中检索标签模板的路径。
这个模板的层次结构看起来像:
1. tag-{slug}.php
2. tag-{id}.php
3. tag.php
这方面的一个例子是:
1. tag-wordpress.php
2. tag-3.php
3. tag.php
模板层次和模板路径可通过{@see ‘$type_template_hierarchy’}和{@see ‘$type_template’}动态钩子过滤。
和{@see ‘$type_template’}动态钩子,其中`$type`是’tag’。
function get_tag_template() { $tag = get_queried_object(); $templates = array(); if ( ! empty( $tag->slug ) ) { $slug_decoded = urldecode( $tag->slug ); if ( $slug_decoded !== $tag->slug ) { $templates[] = "tag-{$slug_decoded}.php"; } $templates[] = "tag-{$tag->slug}.php"; $templates[] = "tag-{$tag->term_id}.php"; } $templates[] = 'tag.php'; return get_query_template( 'tag', $templates ); }