I want to add a new block to my theme that shows a list of years / months, and the number of posts for each, and allows you to click and see those posts, in the same way that you can with tags.
I do not see any obvious way to do this from the API, any pointers?
I have a page in my theme called archive.hbs that I use to do what you’re saying. It may not cover your exact criterion but it should help as a good starting place. Here’s an example of the code:
Yeah, this is something I will have to figure out eventually, as I do believe it’s the most ideal setup. It’s definitely on my list of tasks to complete.
If you learn anything in the meantime, please share!
This is probably best done with some custom coding. One option could be to write a new template “helper” that would create new template tags to use. Examples of how the current template tags specific to Ghost are implemented is here:
Generating this list by looping through all the posts in the database in JavaScript could be somewhat inefficient, though. A more efficient approach could be to write some custom database/SQL code that directly returns a unique list of months or years that posts were created in, and the number associated with is.
I don’t see a shortcut to complete this task using just HTML/CSS/JavaScript in a theme template that performs efficiently once the number posts grows large.
I’ve starting to get the feeling that what I want isn’t possible right now / would require an update to the API, which is strange to me since it seems like a standard feature of every other blog platform I have looked at.
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.
This navigation scheme is entirely for me, the site is not going to be used in any kind of commercial context.
I am going to be using this site a personal journal that I can share with close friends and family. I am currently using google blogger for this purpose, but am looking for other options, since I don’t really like blogger’s interface, and would eventually like to be self hosted.
my ultimate plan with ghost is to try and create an addon that would allow me to integrate with google photos, which is currently the only reason I am still using blogger. I will likely be creating another post about that eventually, but so far I get the feeling that ghost isn’t quite ready for my use case.
For Google photos, you can likely drag and drop photos from there into Ghost.
If you’ve got some coding experience, you write a small script for your server which makes a SQL call like one of the ones above and formats the result as JSON or HTML and writes it out to a web-visible file. This could happen on a timer, like once an hour, or once per day.
Then in a theme file, you could read that JSON or HTML file to complete a navigation scheme.
You could also possibly just maintain the navigation as some static HTML in your theme. That could involve adding a line of HTML once per month.
Dragging and dropping from google photos does not work, but copy paste does.
with google blogger, it’s able to link to the images, rather than copy them into the post but copying seems to work so I guess I could call that a solution, if storage limits aren’t a concern.
regarding the dates, is there any possibility that something like this will be added to the API eventually?
so you could do something like
{{#get “dates” include=“count.posts” limit=“all” as |dates|}}
then the last major thing that seems to be missing is an official app. My understanding is that there was one that was discontinued. do you know if there is any plan to bring it back ever?