Debian Codegraph @

docs/content/en/methods/pages/GroupByLastmod.md

raw
1 ---
2 title: GroupByLastmod
3 description: Returns the given page collection grouped by last modification date in descending order.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.PagesGroup
9 signatures: ['PAGES.GroupByLastmod LAYOUT [SORT]']
10 ---
11
12 When grouping by last modification date, the value is determined by your [project configuration], defaulting to the `lastmod` field in front matter.
13
14 The [layout string] has the same format as the layout string for the [`time.Format`] function. The resulting group key is [localized](g) for language and region.
15
16 [`time.Format`]: /functions/time/format/
17 [layout string]: #layout-string
18 [project configuration]: /configuration/front-matter/#dates
19
20 {{% include "/_common/methods/pages/group-sort-order.md" %}}
21
22 To group content by year and month:
23
24 ```go-html-template
25 {{ range .Pages.GroupByLastmod "January 2006" }}
26 <p>{{ .Key }}</p>
27 <ul>
28 {{ range .Pages }}
29 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
30 {{ end }}
31 </ul>
32 {{ end }}
33 ```
34
35 To sort the groups in ascending order:
36
37 ```go-html-template
38 {{ range .Pages.GroupByLastmod "January 2006" "asc" }}
39 <p>{{ .Key }}</p>
40 <ul>
41 {{ range .Pages }}
42 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
43 {{ end }}
44 </ul>
45 {{ end }}
46 ```
47
48 The pages within each group will also be sorted by last modification date, either ascending or descending depending on your 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:
49
50 ```go-html-template
51 {{ range .Pages.GroupByLastmod "January 2006" }}
52 <p>{{ .Key }}</p>
53 <ul>
54 {{ range .Pages.ByTitle }}
55 <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
56 {{ end }}
57 </ul>
58 {{ end }}
59 ```
60
61 ## Layout string
62
63 {{% include "/_common/time-layout-string.md" %}}