Insert data at specific @index in foreach loop


I’m developing a ghost theme and I have a personalized page that displays the list of posts that have been published. For this I use the foreach loop to display the posts.
I would like to a specific index of the foreach, insert a particular data and make all the other posts shift one position to continue to display following this data. As if I was inserting a value at index 3 of my list actually.
Do you know how I can go about it?

This recent tutorial below accomplishes basically what you’re describing, although not with @index. It uses @foreach with the from and to parameters, so you can do your first N posts, then add your special content, then do the remaining posts.


Thanks, very helpful. That’s what i was looking for

1 Like