<!--
  canonical-url: https://www.avonture.be/blog/docusaurus-number-of-posts
  published:     2024-01-08
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Getting the number of published posts

> Learn the quick and easy way to display the total number of published blog posts on your Docusaurus site using custom components and theme API.

---
![Getting the number of published posts](/img/v2/docusaurus_tips.webp)

**TL;DR**

This article shows a quick trick to count published Docusaurus blog posts: open the auto-generated `/blog/archive/` page, open the browser's developer console, and run a `document.querySelectorAll` instruction against the list of post entries to get the total count.

Docusaurus didn't provide an easy way to retrieve the number of blog posts but there is a trick.

*If you need that count **inside** your site rather than once in a console, the helper built in [Displaying related posts below our Docusaurus article](/blog/docusaurus-relatedposts) already parses every post's front matter and can be reused for this.*

There is an automatic page called `archive` like [/blog/archive/](/blog/archive/).

On that page, all blog posts are displayed by year and months. With a `document.querySelectorAll` console instruction it's possible to make the count as suggested on <https://github.com/facebook/docusaurus/discussions/9712>

![The archive page](./images/archive.webp)

Once the archive page has been displayed, press `F12` to start the **Developer console**.

Click on the `Console` tab then, in the right bottom part, copy/paste the instruction below.

```js
document.querySelectorAll("#__docusaurus_skipToContent_fallback > main > section > div > div > div > ul > li")
```

The first time, the console will notify you that you should allow pasting (in French *autoriser le collage*). Please type `allow paste` to confirm.

Then copy/paste again.

The `document.querySelectorAll` instruction will retrieve every bullet i.e. the list of posts. You'll immediately see the number, in my case, as illustrated below, `51`:

![Console](./images/console.webp)
