How to limit display of featured posts to only 1

Could any of you help me out tweaking the code below?

            {{#get "posts" include="tags,author" filter="featured:true" limit="1" as |featured|}}
                {{#foreach featured}}
                    {{> "post-card" shouldBeLarge="true"}}
                {{/foreach}}
            {{/get}}
            {{#foreach posts}}
                {{#unless featured}}
                    {{> "post-card"}}
                {{/unless}}
            {{/foreach}}      

Here are my “needs”: I only want one post to be shown as featured in the live site no matter what the content in the backend says. How could I tweak that code so it only gets 1 featured post, and the rest of the featured posts still show up as regular posts in the list below ?

I’m simply trying to prevent editors from having to go back to the admin panel to untick the “featured” in older posts. Also, I still want to have 1 featured post for each tag of my site.

I can’t think of a way to do this with handlebars. But a workaround might be to hide the first featured post with CSS in your second loop. So, you can remove the #unless helper and show all the posts, including featured ones. Then, using the {{ post_class }} helper in the post-card partial will generate the fatured class, which you can target its first child with CSS.

1 Like

Brilliant @ahmadajmi !! I think that might work very well!! Tomorrow I’ll test that out and let you know, but I’m very confident!

Thank you for the insight! (I’m still learning the quirks of ghost and handlebars working together)

1 Like