Filter Posts by Date Block

The solution by @denvergeeks would work, but involves selecting the details of every post from the database, sending a lot of data to the frontend that will be discarded, and then having the browser process every post to come up with the result. Here’s example of what it looks like to query this data directly using SQL. I’ve provided an example of querying the by-month counts and also by-year counts. You can see the report that both queries take “0.00” seconds for a small dataset, and this would be a tiny amount of data to transfer to the frontend, even if there were thousands of posts.

Ghost could extend the Content API to support queries like this.

But as someone who has posted content online for over 20 years, I’ll ask:

Is this this navigation scheme for you, or is it for your users? I used to have my blog organized like that, and I have never once received feedback from someone who said they really appreciated that they could select my blog posts by year to read historical content.

If anyone is staying on my site to read more than one post, they are probably looking for “related” content, either content that has a related tag or maybe the “previous” post.

While I’m sure there are exceptions, organizing navigation by topic seems more user-centered. If people want to read old content, I’m OK if they have to select a topic or search for it.

mysql> select DATE_FORMAT(published_at,'%Y-%m') as yyyy_mm, 
                     count(*) as count 
                     from posts 
                     group by yyyy_mm 
                     order by yyyy_mm;
+---------+-------+
| yyyy_mm | count |
+---------+-------+
| 2004-01 |     1 |
| 2006-02 |     1 |
| 2006-05 |     1 |
| 2006-08 |     1 |
| 2007-02 |     1 |
| 2007-08 |     1 |
| 2008-11 |     2 |
| 2009-01 |     1 |
| 2009-08 |     1 |
| 2009-11 |     2 |
| 2010-01 |     2 |
| 2010-12 |     2 |
| 2015-11 |     1 |
| 2016-04 |     1 |
| 2016-08 |     2 |
| 2020-11 |     1 |
| 2021-02 |     1 |
| 2021-10 |     1 |
| 2022-02 |     1 |
| 2022-06 |     1 |
+---------+-------+
20 rows in set (0.00 sec)

mysql> select DATE_FORMAT(published_at,'%Y') as yyyy, 
                       count(*) As count 
                       from posts 
                       group by yyyy 
                       order by yyyy;
+------+-------+
| yyyy | count |
+------+-------+
| 2004 |     1 |
| 2006 |     3 |
| 2007 |     2 |
| 2008 |     2 |
| 2009 |     4 |
| 2010 |     4 |
| 2015 |     1 |
| 2016 |     3 |
| 2020 |     1 |
| 2021 |     2 |
| 2022 |     2 |
+------+-------+
11 rows in set (0.00 sec)