BACK TO TOP

How to Display the Total Number of Posts on Your WordPress Website

How to Display the Total Number of Posts on Your WordPress Website

Regardless of the kind of website you are running, it is the content which you create that keeps visitors returning to your website. If you are looking for a way to display the total number of posts on your blog, whether to show off the sheer amount of high quality content you have created, or to let them know how much reading they‘re getting into, you’re in the right place.

WordPress, while being versatile as it is, does not feature a simple, one-click way of displaying the total number of your posts. We will be showing you two easy ways to do it. But before we do, we‘d like to take some time to discuss how and when this might be useful. Here‘s what we‘ll be talking about:

Blog & Magazine Themes
Behold banner
Behold

Personal Blog WordPress Theme

Buzzy banner
Buzzy

Creative Magazine Theme

Journo banner
Journo

Creative Magazine & Blog Theme

Why and Where to Display the Total Number of Posts on Your Website

A post is the basic unit of a blog, and it is also one of the principal functionalities of a WordPress website. There‘s a lot we can say about creating a blog post, but creating posts is basically what people do when they are “running a blog“. So what does it matter how many posts there are on a website?

Well, the word “blog” is short from the portmanteau word “weblog” or “web log” – a web journal of sorts – and that‘s how blogs started. So if you are running a blog which has a beginning and an end; a whole series of posts which are interconnected or part of a single narrative which is best enjoyed in order, then it makes sense that a reader would want to know how much content there is in total.

On the other hand, you may just want to show off your productivity or the sheer amount of content you have accumulated. This kind of flexing might make sense for any blog driven by the completionist mentality: if each post is a book or film you’ve reviewed, the greater the number the broader your scope. The same can be applied to product review websites, public journals, blogs with multiple contributors, or similar websites.

On a post level, you can do it by displaying the estimated reading time for a post, but on a website level, what you need is a way of displaying the total number of posts.

As for the where part of the question, the methods we will be demonstrating here are not limiting, but we suggest a place on the home page or the page which contains your posts. If you have an unused spot in the header or the footer of this page, this might be a great way of filling it out. You could also try using it at the bottom of each post, as a sort of a signature.

How to Display the Total Number of Posts Using a Plugin

As is so often the case in situations when a functionality is not readily provided by WordPress, you can get the result you want with a plugin. The plugin we will be using is Simple Blog Stats. This plugin provides you with the option to display oodles of stats, including the one we will be concentrating on: the total number of blog posts.

First, you need to install and activate the plugin.

After having installed and activated the plugin, you need to find the stat you want to display, which, in this case, is the number of posts. Navigate to Settings/Simple Blog Stats from your WordPress dashboard.

Simple Blog Stats

You will be taken to the plugin’s settings screen. Once there, open the Shortcodes section.

Shortcodes

This is where you can find a set of shortcodes which are available for you after you have installed your plugin. They work how any shortcode works: as part of a Gutenberg shortcode block, Elementor shortcode element, or as part of any shortcode-ready area.

The first shortcode up should be the shortcode you need: copy the number of posts [sbs_posts] shortcode.

Copy Code

You can now post it anywhere you want it on your website. We will display it as part of a post. We will also be using the default Gutenberg WordPress block editor.

We have started off with a new post with some placeholder text. To add a shortcode to the text, you need a shortcode block. To add a shortcode block, click on the plus sign and find the shortcode block in the menu.

Shrotcode Block

Next, paste the shortcode you want into the block‘s field.

Paste Code

Click publish, and your total post number will appear where you placed it.

Code Preview

By default, this shortcode will simply show the number of all published posts. Now, this shortcode can be modified using the following parameters:

cat for category;
tag for tag;
type for post type; and
status for post status.

For instance, the shortcode [sbs_posts cat=”lifestyle” tag=”food” type=”restaurant_review” status=”draft”] will display the total number of posts from the lifestyle category, tagged with food, belonging to the type restaurant_review which are currently drafts. This can be especially useful if you have your categories and tags straight.

If you want to display the number of posts at the bottom of each of your posts, we suggest you export any blocks you want to use later.

How to Display the Total Number of Posts Using Code

You can, of course, use code to create a shortcode which performs a similar function. To do that, you need to add two pieces of code to your website, though, if you are not a seasoned, coding-savvy WordPress user, we strongly recommend you try using a plugin. We promise it will work much the same as with a plugin.

If you are going to do any direct modifications to your code, we suggest you create a child theme. Additionally, it would be smart to back up everything.

To modify your website‘s files, navigate to your theme editor by selecting Appearance/Theme Editor.

Appearance Theme Editor

Find your website‘s functions.php file in the right hand-side menu. Ours, as most are, is called Theme Functions. Yours may be called differently, depending on the theme you are using, but it will always have functions.php underneath.

Functions

In it, you need to paste the following code:

function my_total_posts() {
$total = wp_count_posts()->publish;
return $total;
}
add_shortcode('total_posts','my_total_posts');

Double-check everything and make sure no other code is disturbed. It is probably best to just scroll all the way down and append this code to the end of your functions.php file. When done, click Update File.

Add Code Update File

And there you have it, you‘re all set. Use the [total_posts] shortcode in a shortcode block or any widget-ready area, the same as described above in the plugin section.

In Conclusion

As you can see, while WordPress does take some fiddling with before you can display the total number of your WordPress posts, it‘s really no big deal and can probably be done in less than a minute, if you‘re really fast. Whether by code or by plugin, you know what to do.

Post your comment

Comments0