简体   繁体   中英

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.

I have tried everything and can't get it to work. Here's the closest I have gotten:

.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. Note that I've used primary_tag which stops duplicate posts from happening. If you don't mind that you can change primary_tag to 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM