Debian Codegraph @

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

raw
1 ---
2 title: GroupByParamDate
3 description: Returns the given page collection grouped by the given date parameter in descending order.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.PagesGroup
9 signatures: ['PAGES.GroupByParamDate PARAM LAYOUT [SORT]']
10 ---
11
12 ## Usage
13
14 The [layout string](#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 {{% include "/_common/methods/pages/group-sort-order.md" %}}
17
18 To group content by year and month:
19
20 ```go-html-template
21 {{ range .Pages.GroupByParamDate "eventDate" "January 2006" }}
22 <p>{{ .Key }}</p>
23 <ul>
24 {{ range .Pages }}
25 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
26 {{ end }}
27 </ul>
28 {{ end }}
29 ```
30
31 To sort the groups in ascending order:
32
33 ```go-html-template
34 {{ range .Pages.GroupByParamDate "eventDate" "January 2006" "asc" }}
35 <p>{{ .Key }}</p>
36 <ul>
37 {{ range .Pages }}
38 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
39 {{ end }}
40 </ul>
41 {{ end }}
42 ```
43
44 The pages within each group will also be sorted by the parameter 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:
45
46 ```go-html-template
47 {{ range .Pages.GroupByParamDate "eventDate" "January 2006" }}
48 <p>{{ .Key }}</p>
49 <ul>
50 {{ range .Pages.ByTitle }}
51 <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
52 {{ end }}
53 </ul>
54 {{ end }}
55 ```
56
57 ## Layout string
58
59 {{% include "/_common/time-layout-string.md" %}}
60
61 [`time.Format`]: /functions/time/format/