简体   繁体   English

获取已发布帖子的所有标签Wordpress

[英]get all tags of published posts Wordpress

How do I fetch all tag names (with ID and count) from all published posts? 如何从所有已发布的帖子中获取所有标签名称(带有ID和计数)?

I know there is wp_tag_cloud but I only want an array of all tags. 我知道有wp_tag_cloud但是我只想要一个包含所有标签的数组。

Check out get_terms() to retrieve the terms in a given taxonomy: 检出get_terms()以检索给定分类法中的术语:

http://codex.wordpress.org/Function_Reference/get_terms http://codex.wordpress.org/Function_Reference/get_terms

Examples: 例子:

$categories = get_terms( 'category',    'orderby=count&hide_empty=0' );

$tags       = get_terms( 'post_tag',    'orderby=count&hide_empty=0' );

$myterms    = get_terms( 'my_taxonomy', 'orderby=count&hide_empty=0' );

This works for me along with tags count. 这与标签计数一起对我有用。

<?php
$tags = get_tags();
if ($tags) {
?><ul class="tags"><?php
foreach ($tags as $tag) {
    echo '<li><a href="' . get_tag_link( $tag->term_id ) . '" 
          title="' . sprintf( __( "View all posts in %s" ), $tag-
          >name ) . '" ' . '>' . $tag->name.' (' . $tag->count . ')</a></li>';
}
echo '<li><a href="#">View All</a><span class="arrow"></span>
</li>'; ?></ul>
<?php }?>   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM