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