How to take first post from the loop


#1

Hi, I want to take the first post from the posts list to make it a different style. I used this code but it doesn’t work.
Can you take a look on it?

{{#foreach posts}}
    {{#has number="nth:1"}}
        <h4><a href="{{url}}" class="card-title">Long posts</a></h4>
    {{/has}}
    <h4><a href="{{url}}" class="card-title">Short post</a></h4>
{{/foreach}}

Please let me know


#2

@ENAMUL_HAQUE I think you want {{#has number="1"}} because you only want the single first post.

The nth:x syntax is saying “every x posts”, in your case because you’ve set it to "1" you’re effectively saying “every other post”.


#3

Thank you for your reply.

I want my first post should come from different post card.
Like this:

{{#foreach posts}}
    {{#has number="nth:1"}}
        {{> "post-card-full"}}
    {{/has}}
    {{> "post-card"}}
{{/foreach}}

But it is not working. All odd number posts are coming from this {{> "post-card-full"}} card.

How can I show only the first post?

Thanks


#4

I explained above :wink: You need number="1" not number="nth:1"


#5

Thanks a lot. The problem is solved