WordPress函数get_category_template()

描述:

检索当前模板或父模板的类别模板路径。

通过检索当前类别编号(如’category-1.php’)可查到该类别的模板路径,若类别编号不存在,则退回category.php模板。

用法:

<?php get_category_template() ?>

参数:

None.

源文件:

function get_category_template() {
    $category = get_queried_object();
 
    $templates = array();
 
    if ( ! empty( $category->slug ) ) {
 
        $slug_decoded = urldecode( $category->slug );
        if ( $slug_decoded !== $category->slug ) {
            $templates[] = "category-{$slug_decoded}.php";
        }
 
        $templates[] = "category-{$category->slug}.php";
        $templates[] = "category-{$category->term_id}.php";
    }
    $templates[] = 'category.php';
 
    return get_query_template( 'category', $templates );
}