Displaying 3 posts of each tags on index


#1

I’m trying to add blocks on my homepage that would display up to 3 featured posts of every (public) tags I have on my blog.

I tried to do it with:

        {{#foreach tags}}
            <div class="tag-list">
                {{#get "posts" filter="tags:{{slug}}+featured:true" limit="3"}}
                    {{#foreach posts}}
                        {{> "post-card"}}
                    {{/foreach}}
                {{/get}}
                <h2>{{name}}</h2>
            </div>
        {{/foreach}}

But I got nothing, probably for the same reason that {{tags}} returns nothing on the home page, because {{tags}} appears to be only available on post context, not on index context.

Is there another way to do it?

I guess I could get posts for each tag by calling each one of them by name manually but I’d rather have something automatic through a loop.


#2

For the record, I tried giving the post context by wrapping the whole code inside a

{{#foreach posts}}
    …
{{/foreach}}

But {{tags}} would returns all occurences of a tag, like if I got 5 posts with the tag “foo”, {{tags}} would returns “foo foo foo foo foo”, which seems legit but not quite something I can work on because of the duplication.


#3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.