mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
9b0050e9aa
git-subtree-dir: docs git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2 KiB
2 KiB
title | description | categories | keywords | action | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GroupByDate | Returns the given page collection grouped by date in descending order. |
|
When grouping by date, the value is determined by your site configuration, defaulting to the date
field in front matter.
The layout string has the same format as the layout string for the time.Format
function. The resulting group key is localized for language and region.
{{% include "methods/pages/_common/group-sort-order.md" %}}
To group content by year and month:
{{ range .Pages.GroupByDate "January 2006" }}
<p>{{ .Key }}</p>
<ul>
{{ range .Pages }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
To sort the groups in ascending order:
{{ range .Pages.GroupByDate "January 2006" "asc" }}
<p>{{ .Key }}</p>
<ul>
{{ range .Pages }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
The pages within each group will also be sorted by date, either ascending or descending depending on the grouping option. To sort the pages within each group, use one of the sorting methods. For example, to sort the pages within each group by title:
{{ range .Pages.GroupByDate "January 2006" }}
<p>{{ .Key }}</p>
<ul>
{{ range .Pages.ByTitle }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
Layout string
{{% include "functions/_common/time-layout-string.md" %}}