sondang
September 24, 2017, 11:40am
1
original code
<ul>
{{ range first 5 ( where ( where .Site.Pages.ByDate.Reverse ".Params.tags" "intersect" .Params.tags ) "Permalink" "!=" .Permalink ) }}
<li class="relatedPost">
<a href="{{ .RelPermalink }}">{{ .Title | markdownify }}</a><br />
{{ .Description | markdownify }}
</li>
{{ end }}
</ul>
Shortcode
<ul>
{{ range first 5 ( where ( where .Site.Pages.ByDate.Reverse ".Params (.Get 0)" "intersect" .Params (.Get 0 ) "Permalink" "!=" .Permalink ) }}
<li class="relatedPost">
<a href="{{ .RelPermalink }}">{{ .Title | markdownify }}</a><br />
{{ .Description | markdownify }}
</li>
{{ end }}
</ul>
Single post
{{< related hugo >}}
always error. I’ve tried various ways still error.
how to fix it?
thank you
bep
September 24, 2017, 3:17pm
2
Not sure what your error is (you should add the error message to your post), but I suggest you have a look at this:
1 Like
sondang
September 24, 2017, 5:09pm
3
ERROR 2017/09/25 00:04:25 Failed to add template "shortcodes/related.html" in path "/home/sondang/Documents/berita/layouts/shortcodes/related.html": template: shortcodes/related.html:2: unclosed left paren
ERROR 2017/09/25 00:04:25 shortcodes/related.html : template: shortcodes/related.html:2: unclosed left paren
Started building sites ...
ERROR 2017/09/25 00:04:25 Unable to locate template for shortcode "related" in page "post/10 distro terbaik 2017.md"
I am now using related content but I want to know how to fix my problem
thank you
rdyar
September 24, 2017, 5:22pm
4
sounds a lot like what I posted yesterday:
well that was easy, scratch to the rescue.
Here is what works:
{{ $.Scratch.Add "servicetype" (.Get 0) }}
{{ range .Site.Data.products.items }}
{{ if eq .featured ($.Scratch.Get "servicetype") }}
<div class="service-flexitem">
<a href="{{.url}}">
<img alt="" src="/assets/img/icons/{{.icon}}" class="img-responsive-hm">
</a>
<div class="service-text">
<a class="servicea" href="{{.url}}"><h3 class="serviceh2">{{.t…
rdyar
September 24, 2017, 5:26pm
5
could also be that. You are missing one at the end I think.
sondang
September 24, 2017, 5:49pm
6
i tried your code but your code is still error.
now I use related content given @bep and it’s better than related post from me.
rybi
September 24, 2017, 10:27pm
7
You had a right parenthesis missing in the first line, this should be correct:
<ul>
{{ range first 5 ( where ( where .Site.Pages.ByDate.Reverse ".Params (.Get 0)" "intersect" .Params (.Get 0 ) "Permalink" "!=" .Permalink )) }}
<li class="relatedPost">
<a href="{{ .RelPermalink }}">{{ .Title | markdownify }}</a><br />
{{ .Description | markdownify }}
</li>
{{ end }}
</ul>
sondang
September 25, 2017, 7:46am
8
still an error but the problem before it is finished.
ERROR 2017/09/25 14:42:13 error processing shortcode "shortcodes / related.html" for page "post / archlinux-distro-terbaik.md": template: shortcodes / related.html: 3: 21: executing "shortcodes /related.html "at <where>: wrong number of args for where: want at least 2 got 1
config.toml
[taxonomies]
kategori = "kategori"
tag = "tag"
content post
+++
title = "Archlinux Distro Terbaik"
date = 2017-09-25T14:33:06+07:00
kategori = ["Linux"]
+++
{{< related kategori >}}
shortcodes/related.html
<ul>
{{ range first 5 ( where ( where .Site.Pages.ByDate.Reverse ".Params (.Get 0)" "intersect" .Params (.Get 0 ) "Permalink" "!=" .Permalink )) }}
<li class="relatedPost">
<a href="{{ .RelPermalink }}">{{ .Title | markdownify }}</a><br />
{{ .Description | markdownify }}
</li>
{{ end }}
</ul>