[英]Ghost post filter by tag name
I'm trying to create a sidebar
for my Ghost blog with the tag name and a list of posts with that tag.我正在尝试为我的 Ghost 博客创建一个sidebar
,其中包含标签名称和带有该标签的帖子列表。
I have tried everything and can't get it to work.我已经尝试了一切,但无法正常工作。 Here's the closest I have gotten:这是我得到的最接近的:
.hbs .hbs
{{#foreach tags}}
<h2>{{tag}}</h2>
{{#foreach posts filter="tags:{{slug}}"}}
<a href="{{url}}">{{title}}</a>
{{/foreach}}
{{/foreach}}
Using the #get
helper should solve this.使用#get
helper 应该可以解决这个问题。 Note that I've used primary_tag
which stops duplicate posts from happening.请注意,我使用了primary_tag
来阻止重复帖子的发生。 If you don't mind that you can change primary_tag
to tag
:如果您不介意,可以将primary_tag
更改为tag
:
{{#get "tags" limit="all"}}
{{#foreach tags}}
<h2>{{name}}</h2>
{{#get "posts" limit="all" filter="primary_tag:{{slug}}"}}
{{#foreach posts}}
<a href="{{url}}">{{title}}</a>
{{/foreach}}
{{/get}}
{{/foreach}}
{{/get}}
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.