WP:分享相同标签的帖子数吗


WP: count posts sharing same tag?

欢呼!

我是WP codex的新手。下面是一个我为特定帖子检索标签的代码示例:

<?php
        global $post;
        $post_tags = get_the_tags($post->ID);
        if ($post_tags) {       
            foreach($post_tags as $tag){
            echo '<div class="tag"><a href="' . get_site_url() . '/tag/'    .   $tag->name  . '">' . $tag->name . '</a></div>';
            }
        }
    ?>

问题是,如何检查标签是否也与至少一个其他帖子共享(仅当至少有两个帖子具有相同标签时才显示标签(?基本上我需要的是:

if ($post_tags **AND $post_tags_count > 1**) {  do the rest of the code 

我知道它应该很简单,但却找不到如何做到。附言:$post_tags_count——这只是一个例子,表明我必须计算共享相同标签的帖子。

我相信我可以添加一个$count=0的循环$计数++;但也许WP提供了更好的解决方案?谢谢大家!

好的。这是我自己想出来的。希望它对某人有用:

<?php
    global $post;
    $post_tags = get_the_tags($post->ID);
    if ($post_tags) {       
        foreach($post_tags as $tag){
        $tag_count =  $tag->count;
        if($tag_count > 1){
            echo '<div class="tag"><a href="' . get_site_url() . '/tag/'    .   $tag->name  . '">' . $tag->name . '</a></div>';
        }
    }
}
?>