aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/en/methods/page/Prev.md
blob: cde83b0f27554f54ab8aad6d5b9408c43e3ef69d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: Prev
description: Returns the previous page in a global page collection, relative to the given page. 
categories: []
keywords: []
action:
  related:
    - methods/page/Next
    - methods/page/PrevInSection
    - methods/page/NextInSection
    - methods/pages/Prev
    - methods/pages/Next
  returnType: hugolib.pageState
  signatures: [PAGE.Prev]
toc: true
---

The behavior of the `Prev` and `Next` methods on a `Page` object is probably the reverse of what you expect.

With this content structure:

```text
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
```

When you visit page-2:

- The `Prev` method points to page-3
- The `Next` method points to page-1

{{% note %}}
Use the opposite label in your navigation links as shown in the example below.
{{% /note %}}

```go-html-template
{{ with .Next }}
  <a href="{{ .RelPermalink }}">Prev</a>
{{ end }}

{{ with .Prev }}
  <a href="{{ .RelPermalink }}">Next</a>
{{ end }}
```

## Compare to Pages methods

{{% include "methods/_common/next-prev-on-page-vs-next-prev-on-pages.md" %}}