Show the amount of posts in a tag in a specific category has
Question
I am creating a page template in WordPress that displays multiple tags that are in a particular category. I have this working, but now I want to have the number of posts within each tag that is displayed as well like if I had a tag called apples with 5 posts it would look like this:
Apples(5)
As of now it just shows Apples
Here is my code I want to modify:
<?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>";
?>
0
4 months
0 Answers
14 views
0
Leave an answer
You must login or register to add a new answer .