Range pages by date not working for 'folders'

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

‘Post 1’ and ‘Post 2’ (which are pages) are sorting according to date, but not ‘Blogs’ (which is a list).

I think that is expected, since the date is empty.

BTW, if you want to display the regular pages only, please use .RegularPagesRecursive instead of .Pages.

1 Like

The date field for Blogs (_index.md) is empty but it seems to be automatically using the date of the most recent post within it’s folder directory (blogs folder). Therefore I don’t understand why it can’t correctly sort my date on my home page.

I think you have a fundamental misunderstanding of (a) content structure and (b) page collections.

Content structure

This is what you have now:

├── blogs/
│   ├── _index.md
│   ├── blog 1.md
│   └── blog 2.md
├── post 1.md
├── post 2.md
├── post 3.md
├── post.md
└── recent.md

This is what is should be:

├── blogs/
│   ├── _index.md  <-- uses list template; range through .Pages
│   ├── blog-1.md
│   └── blog-2.md
├── posts/
│   ├── _index.md  <-- uses list template; range through .Pages
│   ├── post-1.md
│   ├── post-2.md
│   └── post-3.md
└── _index.md  <-- uses home template


  1. Avoid spaces, capital letters, and special characters in your file names. This guidance is not specific to Hugo.
  2. If you want individual posts published to https://example.org/post-xxx instead of https://example.org/posts/post-xxx, define a permalink pattern in your site configuration.

Page collections

See https://gohugo.io/variables/page/#pages-compared-to-sitepages

Collection of regular pages and only first-level section pages under the current list page.

So, when you range through .Pages on your home page, you get regular pages (e.g., about.html, contact.html and section pages (e.g., posts, blogs).

1 Like

I have put all my posts into a posts folder. However I am unsure how to get my posts to display their links individually on my home page. Rather than my home page showing links for post-1.md, post-2.md, post-3.md, it shows a link for Posts.
I’ve corrected my content file structure as you advised and included a url front matter in my posts.md’s like so:

title: "Post 2"
publishDate: "02 Jan 2006"
url: /posts/post-1

Hello world