【发布时间】:2017-08-20 08:56:11
【问题描述】:
我正在尝试仅在我的博客上对 3 个最近的、'精选' 帖子进行排序,但我目前拥有的 for 循环不允许我排序集合首先显示最近的帖子。
我在下面的内容输出了我博客上的三个最新帖子,但忽略了 where_exp 并同时显示精选和非精选帖子。 如果我在按日期排序后删除 'reverse' 过滤器,它只会对精选帖子进行排序,但会将它们从最旧到最新排序。我尝试在 for 循环之前重新分配 featured-posts 变量以再次按反向日期排序,但它不起作用。
到目前为止,我所做的一切都无法让我在我的网站上显示三个最新的精选帖子,我希望有人能告诉我哪里出错了..
后头事项:
---
post_date: 2017-08-14 00:00:00
featured: true
---
页面循环:
{% 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 %}
输出:
Three most recent posts on the website regardless of whether they're 'featured' or not.
提前致谢
【问题讨论】: