调用WordPress 文章标签[带文章数统计]

我们都知道 the_tags get_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中使用下面代码即可:

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注