Reputation: 337
I'm trying to sort the 3 most recent, 'featured' posts only on my blog, but the for loop I currently have won't let me sort the collection to show the most recent posts first.
What I have below outputs the three most recent posts on my blog, but ignores the where_exp and displays both featured and non-featured posts. If I remove the 'reverse' filter after the sort by date it will only sort featured posts, but sorts them oldest to newest. I've tried reassigning the featured-posts variable to sort by reverse-date again before the for loop but it doesn't work.
Everything I've tried so far won't let me display the three most recent, featured posts in my site, I'm hoping someone can tell me where I'm going wrong..
Post Front matter:
---
post_date: 2017-08-14 00:00:00
featured: true
---
Page For-Loop:
{% assign sorted-posts = site.posts | sort: 'post_date' | reverse %}
{% assign featured-posts = sorted-posts | where_exp:"post","post.featured" %}
{% for post in featured-posts limit:3 %}
<h2><a href="{{ post.url }}">{{ post.title | truncate: 58 }}</a></h2>
{% endfor %}
Output:
Three most recent posts on the website regardless of whether they're 'featured' or not.
Thanks in advance
Upvotes: 4
Views: 1828
Reputation: 1220
I met the same problem which confuses me a lot. Finally I found that it's becuase of the web cache. Using Ctrl + F5
to force refresh the page is okay then.
Upvotes: 1
Reputation: 337
Solved by upgrading Jekyll. I was running version 3.0.0, upgraded to 3.5.2 and the issue has been resolved.
Upvotes: 4