mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
Merge commit '00c4484c7092181729f6f470805bc7d72e8ad17b'
This commit is contained in:
@@ -1,25 +1,22 @@
|
||||
---
|
||||
title: Related Content
|
||||
linkTitle: Related Content
|
||||
description: List related content in "See Also" sections.
|
||||
date: 2017-09-05
|
||||
categories: [content management]
|
||||
keywords: [content]
|
||||
menu:
|
||||
docs:
|
||||
parent: "content-management"
|
||||
weight: 40
|
||||
weight: 30
|
||||
draft: false
|
||||
aliases: [/content/related/,/related/]
|
||||
parent: content-management
|
||||
weight: 110
|
||||
toc: true
|
||||
weight: 110
|
||||
aliases: [/content/related/,/related/]
|
||||
---
|
||||
|
||||
|
||||
Hugo uses a set of factors to identify a page's related content based on Front Matter parameters. This can be tuned to the desired set of indices and parameters or left to Hugo's default [Related Content configuration](#configure-related-content).
|
||||
|
||||
## List Related Content
|
||||
|
||||
|
||||
To list up to 5 related pages (which share the same _date_ or _keyword_ parameters) is as simple as including something similar to this partial in your single page template:
|
||||
|
||||
{{< code file="layouts/partials/related.html" >}}
|
||||
@@ -27,9 +24,9 @@ To list up to 5 related pages (which share the same _date_ or _keyword_ paramete
|
||||
{{ with $related }}
|
||||
<h3>See Also</h3>
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
|
||||
{{ end }}
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
@@ -39,25 +36,28 @@ To list up to 5 related pages (which share the same _date_ or _keyword_ paramete
|
||||
Here is the list of "Related" methods available on a page collection such `.RegularPages`.
|
||||
|
||||
#### .Related PAGE
|
||||
|
||||
Returns a collection of pages related the given one.
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ $related := site.RegularPages.Related . }}
|
||||
```
|
||||
|
||||
#### .RelatedIndices PAGE INDICE1 [INDICE2 ...]
|
||||
|
||||
Returns a collection of pages related to a given one restricted to a list of indices.
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ $related := site.RegularPages.RelatedIndices . "tags" "date" }}
|
||||
```
|
||||
|
||||
#### .RelatedTo KEYVALS [KEYVALS2 ...]
|
||||
|
||||
Returns a collection of pages related together by a set of indices and their match.
|
||||
|
||||
In order to build those set and pass them as argument, one must use the `keyVals` function where the first argument would be the `indice` and the consecutive ones its potential `matches`.
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ $related := site.RegularPages.RelatedTo ( keyVals "tags" "hugo" "rocks") ( keyVals "date" .Date ) }}
|
||||
```
|
||||
|
||||
@@ -66,6 +66,7 @@ Read [this blog article](https://regisphilibert.com/blog/2018/04/hugo-optmized-r
|
||||
{{% /note %}}
|
||||
|
||||
## Configure Related Content
|
||||
|
||||
Hugo provides a sensible default configuration of Related Content, but you can fine-tune this in your configuration, on the global or language level if needed.
|
||||
|
||||
### Default configuration
|
||||
|
Reference in New Issue
Block a user