Files
2026-07-13 11:58:46 +08:00

1.2 KiB

title, description, categories, keywords, params
title description categories keywords params
ByLanguage Returns the given page collection sorted by language.
functions_and_methods
returnType signatures
page.Pages
PAGES.ByLanguage

When sorting by language, Hugo orders the page collection using the following priority:

  1. Language weight (ascending)
  2. Date (descending)
  3. LinkTitle (ascending)

This method is rarely, if ever, needed. Page collections that already contain multiple languages, such as those returned by the Rotate, Translations, or AllTranslations methods on a Page object, are already sorted by language weight.

This contrived example aggregates pages from all sites and then sorts them by language:

{{ $p := slice }}
{{ range hugo.Sites }}
  {{ range .Pages }}
    {{ $p = $p | append . }}
  {{ end }}
{{ end }}

{{ range $p.ByLanguage }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

To sort in descending order:

{{ range $p.ByLanguage.Reverse }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}