Hi. I’m relatively new to Ghost—I’m working on my second site with it, and my second custom theme—and I’ve run into a dead end. (I’m prototyping the site on Glitch using Ghost 3.0.0)
I want to have an archive index page with no individual entries, but rather a list of months/years, i.e. “January 2020”. Following a month link would then bring you to a page containing all the posts for that month.
I’m having trouble figuring out how to do either of these things. There doesn’t seem to be a way to iterate over post dates using something like {{foreach}}, and I’m also having trouble figuring out how to create a combination of template & route that would result in listing all the posts for a given month.
Any help in approaching either of these problems would be very appreciated!
This renders each post with the date above it in the format of Month and year, e.g. January 2020. They key part is the <article> element has a class which includes the post month as a single digit number, e.g. post-date-1 for January. We can then hook into that class using some CSS:
This CSS will pick out any post which immediately follows a post with a matching post-date-X class. The result is exactly as desired and meets accessibility expectations. Even works with pagination.
Holy cow, thank you so much! This is fantastically helpful, and I would never have figured it out on my own; it didn’t even cross my mind that CSS would factor into the solution.
Here is another implementation of a “Post Archive”, which the developer has kindly included in his free “Fizzy” theme as a custom template (so you can copy it and use in your own site too):
How do I do this?! Looks awesome but a few more hints would be appreciated. Want to add an archive page just like this to the Attila theme and I’m very new at Ghost (since 2020-11-07) after being a long time WordPress user.
Hi, I am looking through this again. Have you come across any themes that do this, but maybe group by month? I would like an archive page for nearly 2K posts over about a 15 year period, and this would be too long. Thought I would ask Thanks.
@DavidDarnes The code you shared needs to be embedded in one of the base files that comes with the downloaded theme, or do I need to create a new .hbs file. I’m using this code with the Alto and Dawn themes and can’t seem to get it to work. I have very minimal web development knowledge and would appreciate any extra input you can share.
Thanks so much, I’m glad to have joined this forum and excited to learn from other members.