How to limit front-filtered messages?

I have a Jekyll blog where some posts have "great images", some posts don't work.

Selected images are defined in the front of the message, for example: featured-image: http://path/to/img

On the archive page, I would like to capture the last three posts in which there are images and their display.

I assume that for this you need an if statement, a counter and a loop, but I cannot get this to work for me:

 <ul id="archive-featured"> {% assign count = '0' %} {% if count < '4' %} {% for post in site.posts %} {% if post.featured-image == true %} {{ count | plus: '1' }} <li><a href="{{ post.url }}"><img src="{{post.featured-image}}" />{{ post.title }}</a></li> {% endif %} {% endfor %} {% endif %} </ul> 

What am I missing?

+4
source share
1 answer

Your YAML case looks good, but I'm not sure you need to set up an account to do the job. Try using a limit to limit the number of messages assigned to you on the archive page. You also do not need to assign a "true" value to the {% if %} operator:

 <ul id="archive-featured"> {% for post in site.posts limit:3 %} {% if post.featured-image %} <li> <a href="{{ post.url }}"> <img src="{{ post.featured-image }}" /> {{ post.title }} </a> </li> {% endif %} {% endfor %} </ul> 

I believe that posts are automatically displayed as the last post, so no extra work is required there. Hope this helps!

+2
source

All Articles