Show Total Post Count on Homepage
-
Hello,
I have built a referral website about themes and other web developing resources, which is run using a plugin from Envato.
Since the plugin is run automatically, it adds new posts several times a day, and what I want, is to show the post count on the home page. For example;
5,000 Website Themes, Graphics and Add-ons from $3
Now, I have achieved this, but with some formatting errors (more like personal preferences not being met).
I am using this code to get the post count:
<?php $postcount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); echo number_format($postcount, 0); ?> Website Themes, Graphics and Add-ons from $3
However, for reasons I am not sure why, the code above outputs a number that is actually higher than the published post count.
The code below, displays the post count correctly, going by the number of actual posts created in the “Posts” area of WordPress:
<?php $count_posts = wp_count_posts(); echo $count_posts->publish; ?> Website Themes, Graphics and Add-ons from $3
But the code shows the output like this: “5000” and not “5,000” as I would like it.
So, my question to you, is how can I use the second code that displays the correct amount of posts, with the correct formatting (5,000) and not (5000).
I hope I have explained this correctly!
Any help is greatly appreciated!
Kind regards
- The topic ‘Show Total Post Count on Homepage’ is closed to new replies.