WP获取分类的链接

【WP获取分类的链接】我正在使用以下变量来显示类别名称。

< ?php $postcat = get_the_category( $post-> ID ); ?>


< ?php echo esc_html($postcat[0]-> name ); ?>

我如何获得类别的链接?
示例:www.example.com/category/business
#1很简单, 你可以使用get_category_link()函数。
// Get the URL of this category $category_link = get_category_link( $category_id );

#2请使用以下代码, 它将为你完成工作:
$categories = get_the_category(); if ( ! empty( $categories ) ) { echo '< a href="' . esc_url( get_category_link( $categories[0]-> term_id ) ) . '"> ' . esc_html( $categories[0]-> name ) . '< /a> '; }

    推荐阅读