196 字
1 分钟
调用WordPress 文章标签[带文章数统计]
2016-10-30
浏览量:加载中...访问次数:加载中...

我们都知道 the_tagsget_the_tags 可以调用文章标签,但也无非就是调用标签,其实每个标签都包含了很多参数,只调用名字和链接有点太浪费了,所以我们在加上一个小小的文章数统计,瞬间变的高大上起来。

实现方法#

下面的代码加到 functions.php 中:

function fa_get_the_term_list( $id, $taxonomy ) {
$terms = get_the_terms( $id, $taxonomy );
$term_links = "";
if ( is_wp_error( $terms ) )
return $terms;
if ( empty( $terms ) )
return false;
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) )
return $link;
$term_links .= '<a href="' . esc_url( $link ) . '" class="js-loaded post--keyword" data-title="' . $term->name . '" data-type="'. $taxonomy .'" data-term-id="' . $term->term_id . '">' . $term->name . '<sup>['. $term->count .']</sup></a>';
}
return $term_links;
}

调用方法:在loop中使用下面代码即可:

调用WordPress 文章标签[带文章数统计]
https://blog.057000.xyz/posts/2016-10-30-调用wordpress-文章标签带文章数统计/
作者
Feng
发布于
2016-10-30
许可协议
CC BY-NC-SA 4.0