HUGO

[SOLVED] Blog post pagination grouped by date headings

I’d love to be able to group the posts on my blog by date, akin to what Dave Winer has on Scripting.com, but I’m having issues adding it to my barebones theme.

This is what I use in index.html to paginate posts in ./content/post/*:

{{ $paginator := .Paginate (where site.RegularPages "Type" "post") }}
{{ range $paginator.Pages }}
    <h1>{{ .Title }}</h1>
    <time>{{ .Date }}</time>
    [..]
{{ end }}

Which gives me:

Post Title

Date

Post Title

Date

But I’m looking for:

Date

Post Title
Post Title

The pagination docs suggest I can use this:

{{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups  }}

But I’ve been trying to figure out how to merge them with the posts lookup above. Anyone know how I get paginate posts and group them like this?

Brilliant thank you, that did the trick.

(Apologies for the dupe post, searched but didn’t find that thread!)

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