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

来源:

https://www.srcmini02.com/65107.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_41089.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?