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