Option to order sections by date for index.html
Opened this issue · 2 comments
micw commented
In index.html sections are default-ordered (https://gohugo.io/methods/site/regularpages/). Would be nice to have an option to change this order (e.g. by date ascending)
JincanDeng commented
Same problem. Any method to change the order?
micw commented
Here's the way I do it (switchable vie site parameter):
diff --git a/layouts/index.html b/layouts/index.html
index 4b826a1..84a5caf 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -11,6 +11,12 @@
{{ $section_name := . }}
{{/* Create a variable with that section to use in multiple places. */}}
{{ $section := where $.Site.RegularPages "Section" "in" $section_name }}
+
+ {{ if $.Site.Params.order_by_date | default false }}
+ {{ $section = $section.ByDate }}
+ {{ end }}
+
+
{{ $section_count := len $section }}
{{ if ge $section_count 1 }}
<div class="pa3 pa4-ns w-100 w-70-ns center">