WordPress函数get_tag_template()

描述:

在当前或父模板中检索标记模板的路径。此模板的层次结构如下所示:

  • tag-{slug}.php
  • tag-{id}.php
  • tag.php

例如:

  • tag-wordpress.php
  • tag-3.php
  • tag.php

返回值:

(string) 标签模板文件的完整路径。

源文件:

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 );
}