Debian Codegraph @

docs/content/en/methods/pages/Related.md

raw
1 ---
2 title: Related
3 description: Returns a collection of pages related to the given page.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: page.Pages
9 signatures:
10 - PAGES.Related PAGE
11 - PAGES.Related OPTIONS
12 ---
13
14 Based on front matter, Hugo uses several factors to identify content related to the given page. Use the default [related content configuration][], or tune the results to the desired indices and parameters. See [details][].
15
16 ## Usage
17
18 The argument passed to the `Related` method may be a `Page` or an options map. For example, to pass the current page:
19
20 ```go-html-template {file="layouts/page.html"}
21 {{ with .Site.RegularPages.Related . | first 5 }}
22 <p>Related pages:</p>
23 <ul>
24 {{ range . }}
25 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
26 {{ end }}
27 </ul>
28 {{ end }}
29 ```
30
31 To pass an options map:
32
33 ```go-html-template {file="layouts/page.html"}
34 {{ $opts := dict
35 "document" .
36 "indices" (slice "tags" "keywords")
37 }}
38 {{ with .Site.RegularPages.Related $opts | first 5 }}
39 <p>Related pages:</p>
40 <ul>
41 {{ range . }}
42 <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
43 {{ end }}
44 </ul>
45 {{ end }}
46 ```
47
48 ## Options
49
50 `indices`
51 : (`slice`) The indices to search within.
52
53 `document`
54 : (`page`) The page for which to find related content. Required when specifying an options map.
55
56 `namedSlices`
57 : (`slice`) The keywords to search for, expressed as a slice of `KeyValues` using the [`keyVals`][] function.
58
59 `fragments`
60 : (`slice`) A list of special keywords that is used for indices configured as type "fragments". This will match the [fragment](g) identifiers of the documents.
61
62 A contrived example using all of the above:
63
64 ```go-html-template
65 {{ $page := . }}
66 {{ $opts := dict
67 "indices" (slice "tags" "keywords")
68 "document" $page
69 "namedSlices" (slice (keyVals "tags" "hugo" "rocks") (keyVals "date" $page.Date))
70 "fragments" (slice "heading-1" "heading-2")
71 }}
72 ```
73
74 [`keyVals`]: /functions/collections/keyvals/
75 [details]: /content-management/related-content/
76 [related content configuration]: /configuration/related-content/