Theme orders posts alphabetically, how do I change to sort by date?

Hello everyone,

I am using the gochowdown theme, and while I’ve managed to customise it quite well on my own, I am struggling to change the sort order of the posts on the homepage. They are being listed alphabetically, but I want to sort them by date, so the newest post appears first.

I’ve tried poking around a bunch of files, as well as done a lot of web searching and reading the docs, but my knowledge is in HTML and CSS, and not areas which involve what {{- .Data.Singular | title -}} means, for example. Despite my best efforts to try and wrap my head around this, I’m not knowledgable enough to know what or where the section of code is that I need to change. It’s been hours at this point, so I thought I should ask for some assistance now.

Thank you for your time and any help you can give, and I apologise if this has been asked elsewhere, I did search extensively, but maybe I missed something obvious.

https://github.com/seanlane/gochowdown/blob/master/layouts/partials/home.html#L4

Change:

{{ range sort (where .Site.RegularPages "Section" "recipes") "Title" }}

To:

{{ range (where .Site.RegularPages "Section" "recipes").ByDate.Reverse }}

See https://gohugo.io/templates/lists#order-content. Given that you are not specifying weight in each recipe’s front matter, you can also rely on Hugo’s default sort order:

{{ range where .Site.RegularPages "Section" "recipes" }}
1 Like

Worked perfectly! Thank you so much!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.