簡體   English   中英

獲取已發布帖子的所有標簽Wordpress

[英]get all tags of published posts Wordpress

如何從所有已發布的帖子中獲取所有標簽名稱(帶有ID和計數)?

我知道有wp_tag_cloud但是我只想要一個包含所有標簽的數組。

檢出get_terms()以檢索給定分類法中的術語:

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

例子:

$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' );

這與標簽計數一起對我有用。

<?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