显示特定类别标签中的帖子数量

Show the amount of posts in a tag in a specific category has

我正在 Wordpress 中创建一个页面模板,用于显示特定类别中的多个标签。我有这个工作,但现在我想要显示每个标签中的帖子数量,就像如果我有一个名为 apples 的标签有 5 个帖子,它看起来像这样:

Apples(5)

目前只显示 Apples

这是我要修改的代码:


    <?php
      if (is_category()){
           $cat = get_query_var('cat');
           $yourcat = get_category ($cat);
       }
       $tag_IDs = array();
           query_posts('category_name=health');
                   if (have_posts()) : while (have_posts()) : the_post();
                       $posttags = get_the_tags();
                           if ($posttags):
                           foreach($posttags as $tag) {
                               if (!in_array($tag->term_id , $tag_IDs)):
                                   $tag_IDs[] = $tag->term_id;
                                   $tag_names[$tag->term_id] = $tag->name;
                                   endif;
                       }
                       endif;
                       endwhile; endif;
                   wp_reset_query();
       
               echo "<ul>";
               foreach($tag_IDs as $tag_ID){
               echo '<a href="'.get_tag_link($tag_ID).'">'.$tag_names[$tag_ID].'</a>';
               }
           echo "</ul>";
       ?>                                  

我认为您正在寻找以下内容:

在当前查询的循环外:

<?php echo $wp_query->get_queried_object()->count; ?>

在每个术语的循环内:

<?php echo $tag->count; ?>

此致。