How mutual linking can be implemented?

config.tom:

cons  = "/:section/:title/"
pros  = "/:section/:title/"

layouts/
├── 404.html
├── cons
├── _default
├── index.html
├── partials
├── shortcodes
└── pros

Any cons post has a related pros post with the same title. There’s a link to related pros post within cons post and vice versa. What’s the approach to implement this mutual linking?

I was thinking to grab the last part of URLs, the title part. Here is part of a post front matter in /contents/cons:

+++
title= "this is a title"
cons = "sth'
+++

It turns to [DOMAIN]/cons/this-is-a-title

If I grab the this-is-a-title part of URL, I can link to its sister by:

<a href="/pros/{{ putting last prt of url here, somehow }}">Read Pros</a>`

But, how to to grab the last part of URL?

Any better solutions?

1 Like

Thanks. It’s working:

[[related.indices]]
name  = "title"

Another Q: I was using the below code for See Also section in ‘cons’ posts:

{{ range first 5 (where (where .Site.RegularPages "Section" "cons") "Params.pub" "yes") }}
  ...
{{ end }}

Now I see it’s better to use Related Content. My question: currently I’m using this feature by defining name = "title" in confg.toml to link to an individual post. Can I use it for creating a list of related posts too (by name = "ctaegories")? But posts with same categories value are added to that individual post :frowning:

[related]
threshold = 80
includeNewer = false
toLower = false

[[related.indices]]
name  = "title"
weight = 100

[[related.indices]]
name  = "categories"
weight = 150

Also see https://npf.io/2014/08/making-it-a-series/ which is still a good way of connecting on a taxonomy level.

1 Like

Yes, that is the main use case of the related feature.

1 Like