1

fun88体育 调用文章标签[带文章数统计]

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

打算以后函数命名都已fa开头了,既象征着大发又是域名的开头 Loading

实现方法:
下面的代码加到functions.php中
[cc lang="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 .= 'name . '" data-type="'. $taxonomy .'" data-term-id="' . $term->term_id . '">' . $term->name . '['. $term->count .']';
}

return $term_links;
}
[/cc]

调用方法:
在loop中使用下面代码即可
[cc lang="php"]
php echo fa_get_the_term_list( get_the_ID(), 'post_tag' );
[/cc]