Displaying a first post in a different section than the rest of them

Hi, how can I display first post in a different section than rest of them? For example I have document structure like this:

<div class="top-post">MY FIRST POST IN LOOP</div>
<div class="site-posts">MY OTHER POSTS WITHOUT FIRST POST</div>

And how can I separate first post form other?
I’m using latest version of ghost, basic configuration without any changes and I’m making locally my theme.

Simply do a check to see if it is the first iteration of the collection. Like this:

{{#foreach posts}}
	{{#if @first}}
		<div class="top-post">MY FIRST POST IN LOOP</div>
	{{else}}
		<div class="site-posts">MY OTHER POSTS WITHOUT FIRST POST</div>
	{{/if}}
{{/foreach}}
1 Like

You could probably do this by using the from / to attribute in 2 foreach loops (one for the top post and one for the other ones)

1 Like

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