How to display the number of posts on a tag page?

In wordpress (ideally, without using a plug-in) on the tag page, I would like to show the number of posts tagged with the tag.

Example: There are 8 posts tagged "baseball" when you are on the baseball tag page, he says: "There are 8 posts about baseball"

He must dynamically know which page of tags to receive the invoice and print it. I found several options for static input of the name or identifier of the tag and return of the number, but my attempts to make them work dynamically were not available.

This is what I worked with:

$taxonomy = "post_tag"; // can be category, post_tag, or custom taxonomy name // Using Term Name $term_name = single_cat_title; $term = get_term_by('name', $term_name, $taxonomy); // Fetch the count echo $term->count; 

Any help would be greatly appreciated!

+4
source share
3 answers

You can simply print the found_posts property of the WP request object

 echo $wp_query->found_posts; 
+2
source

Open the file in the template named "tag.php" and enter the desired code into it.

0
source

Here is another possible solution from WP Recipes . They were kind enough to post this the day after I received the answer here. :)

 <?php $feat_loop = new WP_Query( 'showposts=12&category_name=featured' ); echo "Query returned ".$feat_loop->post_count." posts."; ?> 

It has a different application, but still very useful!

http://www.wprecipes.com/get-how-many-posts-are-returned-by-a-custom-loop?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Wprecipes+%28WpRecipes.com%3A+Daily+ recipes + to + cook + with + WordPress% 29

0
source

All Articles