diff --git a/exampleSite/content/basics/configuration/_index.en.md b/exampleSite/content/basics/configuration/_index.en.md
index b048313d4b..eefbb1af38 100644
--- a/exampleSite/content/basics/configuration/_index.en.md
+++ b/exampleSite/content/basics/configuration/_index.en.md
@@ -55,7 +55,8 @@ Note that some of these parameters are explained in details in other sections of
mermaidInitialize = "{ \"theme\": \"default\" }"
# Hide Next and Previous page buttons normally displayed full height beside content
disableNextPrev = true
- # Order sections in menu by "weight" or "title". Default to "weight"
+ # Order sections in menu by "weight" or "title". Default to "weight";
+ # this can be overridden in the pages frontmatter
ordersectionsby = "weight"
# Change default color scheme with a variant one. Can be "red", "blue", "green".
themeVariant = ""
diff --git a/exampleSite/content/cont/pages/_index.en.md b/exampleSite/content/cont/pages/_index.en.md
index 8d37d45934..b1a161bc22 100644
--- a/exampleSite/content/cont/pages/_index.en.md
+++ b/exampleSite/content/cont/pages/_index.en.md
@@ -103,6 +103,8 @@ disableToc = "false"
menuTitle = ""
# If set, this will explicitly override common rules for the expand state of a page's menu entry
alwaysopen = true
+# If set, this will explicitly override common rules for the sorting order of a page's submenu entries
+ordersectionsby = "title"
# The title of the page in menu will be prefixed by this HTML content
pre = ""
# The title of the page in menu will be postfixed by this HTML content
diff --git a/exampleSite/content/shortcodes/children/_index.en.md b/exampleSite/content/shortcodes/children/_index.en.md
index 490f1efeed..b9410796e9 100644
--- a/exampleSite/content/shortcodes/children/_index.en.md
+++ b/exampleSite/content/shortcodes/children/_index.en.md
@@ -16,7 +16,7 @@ Use the children shortcode to list the child pages of a page and the further des
| showhidden | "false" | When true, child pages hidden from the menu will be displayed |
| description | "false" | Allows you to include a short text under each page in the list. When no description exists for the page, children shortcode takes the first 70 words of your content. [Read more info about summaries on gohugo.io](https://gohugo.io/content/summaries/) |
| depth | 1 | Enter a number to specify the depth of descendants to display. For example, if the value is 2, the shortcode will display 2 levels of child pages. **Tips:** set 999 to get all descendants |
-| sort | [ordersectionsby]({{% relref "basics/configuration#global-site-parameters" %}}) | Sort children by **weight** - to sort on menu order, **title** - to sort alphabetically on menu label |
+| sort | [ordersectionsby]({{% relref "basics/configuration#global-site-parameters" %}}) | Sort children by **weight**, to sort on menu order - **title**, to sort alphabetically on menu label. If not set it is sorted by the `ordersectionsby` setting of the site and the pages frontmatter |
## Demo
diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html
index aae5934b8e..2177a545d1 100644
--- a/layouts/partials/menu.html
+++ b/layouts/partials/menu.html
@@ -21,8 +21,10 @@
{{- end }}
+ {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
+ {{- $currentOrdersectionsby := .Site.Home.Params.ordersectionsby | default $defaultOrdersectionsby }}
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default false }}
- {{- if eq .Site.Params.ordersectionsby "title" }}
+ {{- if eq $currentOrdersectionsby "title" }}
{{- range .Site.Home.Sections.ByTitle }}
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
{{- end }}
@@ -105,6 +107,8 @@
{{- if $hidden }}
{{- else if .IsSection }}
{{- safeHTML .Params.head }}
+ {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
+ {{- $currentOrdersectionsby := .Params.ordersectionsby | default $defaultOrdersectionsby }}
{{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }}
-
{{- partial "menu-pre.html" . }}{{ or .Params.menuTitle .LinkTitle .Title }}{{ partial "menu-post.html" . }}
@@ -116,7 +120,7 @@
{{- $pages = (.Pages | union .Sections) }}
{{- end }}
{{- $defaultAlwaysopen := .Site.Params.alwaysopen | default true }}
- {{- if eq .Site.Params.ordersectionsby "title" }}
+ {{- if eq $currentOrdersectionsby "title" }}
{{- range $pages.ByTitle }}
{{- template "section-tree-nav" dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen }}
{{- end }}
diff --git a/layouts/partials/page-meta.go b/layouts/partials/page-meta.go
index f7833c0477..0aca0165f1 100644
--- a/layouts/partials/page-meta.go
+++ b/layouts/partials/page-meta.go
@@ -42,7 +42,9 @@
{{- end }}
{{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
- {{- if eq .Site.Params.ordersectionsby "title"}}
+ {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
+ {{- $currentOrdersectionsby := .node.Params.ordersectionsby | default $defaultOrdersectionsby }}
+ {{- if eq $currentOrdersectionsby "title"}}
{{- range $pages.ByTitle }}
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current }}
{{- end}}
diff --git a/layouts/shortcodes/children.html b/layouts/shortcodes/children.html
index 8d15dd2cd7..7558a6901f 100644
--- a/layouts/shortcodes/children.html
+++ b/layouts/shortcodes/children.html
@@ -3,7 +3,7 @@
{{- $style := .Get "style" | default "li" }}
{{- $depth := .Get "depth" | default 1 }}
{{- $withDescription := .Get "description" | default false }}
-{{- $sortTerm := .Get "sort" | default (.Site.Params.ordersectionsby | default "weight") | lower }}
+{{- $sortTerm := .Get "sort" | lower }}
{{- $containerstyle := .Get "containerstyle" | default "ul" }}
{{ (printf "<%s class=\"children children-%s children-sort-%s\">" $containerstyle $style $sortTerm)|safeHTML }}
@@ -14,15 +14,17 @@
{{- $pages = (.Page.Pages | union .Page.Sections) }}
{{- end }}
- {{- if eq $sortTerm "weight" }}
+ {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
+ {{- $currentOrdersectionsby := $sortTerm | default (.Page.Params.ordersectionsby | default $defaultOrdersectionsby) }}
+ {{- if eq $currentOrdersectionsby "weight" }}
{{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
- {{- else if or (eq $sortTerm "name") (eq $sortTerm "title") }}
+ {{- else if or (eq $currentOrdersectionsby "name") (eq $currentOrdersectionsby "title") }}
{{- template "childs" dict "menu" $pages.ByTitle "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
- {{- else if eq $sortTerm "publishdate" }}
+ {{- else if eq $currentOrdersectionsby "publishdate" }}
{{- template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
- {{- else if eq $sortTerm "date" }}
+ {{- else if eq $currentOrdersectionsby "date" }}
{{- template "childs" dict "menu" $pages.ByDate "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
- {{- else if eq $sortTerm "length" }}
+ {{- else if eq $currentOrdersectionsby "length" }}
{{- template "childs" dict "menu" $pages.ByLength "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
{{- else }}
{{- template "childs" dict "menu" $pages "containerstyle" $containerstyle "style" $style "showhidden" $showhidden "count" 1 "depth" $depth "pages" .Site.Pages "description" $withDescription "sortTerm" $sortTerm }}
@@ -69,15 +71,17 @@
{{- $pages = (.Page.Pages | union .Page.Sections) }}
{{- end }}
- {{- if eq $.sortTerm "weight" }}
+ {{- $defaultOrdersectionsby := .Site.Params.ordersectionsby | default "weight" }}
+ {{- $currentOrdersectionsby := $.sortTerm | default (.Page.Params.ordersectionsby | default $defaultOrdersectionsby) }}
+ {{- if eq $currentOrdersectionsby "weight" }}
{{- template "childs" dict "menu" $pages.ByWeight "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
- {{- else if or (eq $.sortTerm "name") (eq $.sortTerm "title") }}
+ {{- else if or (eq $.currentOrdersectionsby "name") (eq $.currentOrdersectionsby "title") }}
{{- template "childs" dict "menu" $pages.ByTitle "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
- {{- else if eq $.sortTerm "publishdate" }}
+ {{- else if eq $.currentOrdersectionsby "publishdate" }}
{{- template "childs" dict "menu" $pages.ByPublishDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
- {{- else if eq $.sortTerm "date" }}
+ {{- else if eq $.currentOrdersectionsby "date" }}
{{- template "childs" dict "menu" $pages.ByDate "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
- {{- else if eq $.sortTerm "length" }}
+ {{- else if eq $.currentOrdersectionsby "length" }}
{{- template "childs" dict "menu" $pages.ByLength "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}
{{- else }}
{{- template "childs" dict "menu" $pages "containerstyle" $.containerstyle "style" $.style "showhidden" $.showhidden "count" (add $.count 1) "depth" $.depth "pages" $.pages "description" $.description "sortTerm" $.sortTerm }}