Display recent posts in the homepage

I have the following in my index.html:

<!-- orders content according to the "publishdate" field in front matter -->
<ul>
{{ range .Pages.ByPublishDate }}
<li>
<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
<time>{{ .Date.Format "2 Jan 2006" }}</time>
</li>
{{ end }}
</ul>

And in each of my posts.md I include the publication date in the front matters, like so:

Title: "Post 1"
publishDate: "1 Jan 2006"
Title: "Post 2"
publishDate: "2 Jan 2006"
Title: "Post 3"
publishDate: "3 Jan 2006"

However my index.html appears as follows, which shouldnā€™t be right, the posts are not in order by date and thereā€™s this ā€˜1 Jan 0001ā€™ displayed on each of them:

Repo: GitHub - jpnfighter/steve-site: hugo website

Which theme are you using?

1 Like

Your site currently displays the one and only content file on the home page. What are you trying to accomplish?

1 Like

Iā€™ve updated the post thanks.

Your date format is incorrect. Numbers between 1 and 9 should have a 0 before them like this 01 Jan 2023.

1 Like

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