HUGO
Menu
GitHub 87548 stars Mastodon

Next

返回站點常規頁面集合中相對於當前頁面的下一個頁面。

Syntax

PAGE.Next

Returns

page.Page

Hugo 根據此排序層次結構對站點的常規頁面集合進行排序來確定 下一個上一個 頁面:

字段 優先級 排序方向
weight 1 降序
date 2 降序
linkTitle 3 降序
path 4 降序

用於確定 下一個上一個 頁面的已排序頁面集合獨立於其他頁面集合,這可能會導致意外行為。

例如,使用此內容結構:

content/
├── pages/
│   ├── _index.md
│   ├── page-1.md   <-- front matter: weight = 10
│   ├── page-2.md   <-- front matter: weight = 20
│   └── page-3.md   <-- front matter: weight = 30
└── _index.md

以及這些模板:

layouts/section.html
{{ range .Pages.ByWeight }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
layouts/page.html
{{ with .Prev }}
  <a href="{{ .RelPermalink }}">上一個</a>
{{ end }}

{{ with .Next }}
  <a href="{{ .RelPermalink }}">下一個</a>
{{ end }}

當您訪問 page-2 時:

  • Prev 方法指向 page-3
  • Next 方法指向 page-1

要反轉 下一個上一個 的含義,您可以在 站點配置 中更改排序方向,或對 Pages 對象使用 NextPrev 方法以獲得更大的靈活性。


Last updated: January 1, 0001
Improve this page