Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 显示特定类别中标签中的帖子数量_Wordpress_Tags_Categories - Fatal编程技术网

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

Wordpress 显示特定类别中标签中的帖子数量,wordpress,tags,categories,Wordpress,Tags,Categories,我正在Wordpress中创建一个页面模板,显示特定类别中的多个标记。我有这个功能,但现在我想在每个标签中显示帖子的数量,就像如果我有一个名为apples的标签,有5篇帖子,它看起来是这样的: Apples(5) 到目前为止,它只显示苹果 以下是我要修改的代码: <?php if (is_category()){ $cat = get_query_var('cat'); $yourcat = get_category ($

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

Apples(5)
到目前为止,它只显示苹果

以下是我要修改的代码:


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

问候