In wordpress (ideally, with out the use of a plug-in) on a tag page I would like to show the number of posts that are tagged with the current tag.
Example:
There are 8 posts with the tag “baseball”
when you are on the tag page for baseball it says, “There are 8 posts about baseball”
It should dynamically know which tag page your on, get the count and print it. I have found several options for statically entering the tag name or ID and returning the count but my attempts to get them to work dynamically have been unsucessful.
This is what I was working 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!
You can just print the
found_posts
property of the WP Query objectOpen the file in your template named “tag.php” and enter the desired code in it.
Here is another possible solution from WP Recipes. They were kind enough to post this the day after I got an answer here. 🙂
It has 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