get_the_category获取wordpress当前post分类

更新时间:2022-06-19 09:57:44 来源:青锋建站 作者:青锋建站
get_the_category
  ( int $post_id = false ),wordpress获得post分类的函数。
get_the_category简介
  这个标签函数用于在循环之外获得当前post分类,传递一个POSTID作为参数。此函数仅返回来自默认的类别分类法的结果,用于自定义分类请使用get_the_terms().函数。
get_the_category参数
  $post_id (int) (Optional)post ID. 缺省值是当前POST ID,默认为false。
get_the_category返回值
  WP_Term对象的数组,分类每个类别中的一个。
get_the_category源代码
  文件wp-includes/category-template.php
function get_the_category( $post_id = false ) {
    $categories = get_the_terms( $post_id, 'category' );
    if ( ! $categories || is_wp_error( $categories ) ) {
        $categories = array();
    }
    $categories = array_values( $categories );
    foreach ( array_keys( $categories ) as $key ) {
        _make_cat_compat( $categories[ $key ] );
    }
    /**
     * Filters the array of categories to return for a post.
     *
     * @since 3.1.0
     * @since 4.4.0 Added `$post_id` parameter.
     *
     * @param WP_Term[] $categories An array of categories to return for the post.
     * @param int|false $post_id    ID of the post.
     */
    return apply_filters( 'get_the_categories', $categories, $post_id );
}

转载请注明来源网址:青锋建站-http://www.sjzphp.com/cmsxitong/wordpressxt/get_the_category_1392.html

地方分站

电话 15632335515 | 邮箱 943703539@qq.com | QQ 943703539 | 微信 qingfengjianzhan

Copyright © 2016-2026 青锋建站 版权所有