0
我使用液体(https://github.com/tobi/liquid/)在我的模板中呈现内容。 我想在我的主页上有一个“最近的活动”部分,它将查找按日期排序的三种不同内容类型的最新更新,限制为四个。将内容类型与液体模板语言结合使用
这是可能的液体?
所以,用通俗易懂的语言查询会是这样的.. “选择由CONTENT_TYPE_1,2或3日期排列的四个最新项目”
感谢, 马克。
我使用液体(https://github.com/tobi/liquid/)在我的模板中呈现内容。 我想在我的主页上有一个“最近的活动”部分,它将查找按日期排序的三种不同内容类型的最新更新,限制为四个。将内容类型与液体模板语言结合使用
这是可能的液体?
所以,用通俗易懂的语言查询会是这样的.. “选择由CONTENT_TYPE_1,2或3日期排列的四个最新项目”
感谢, 马克。
按content_type,我假设你是指帖子的类别。您可以通过添加
category: type_1
到您的文章的YAML Front Matter或把该职位在type_1/_posts
文件夹分类您的帖子。 一旦我们有这个,这是一个稍微俗气的做你想做的事情:
<div>
{% assign count1 = true %}
{% assign count2 = true %}
{% assign count3 = true %}
{% assign count4 = true %}
{% for post in site.posts %}
{% if post.categories contains 'type_1' or post.categories contains 'type_2' or ... %}
{% if count1 == true or count2 == true or count3 == true or count4 == true %}
<li><span>{{ post.date | date_to_string }}</span> » <a href="{{ post.url }}">{{ post.title }}</a></li>
{% if count1 == true %}
{% assign count1 = false %}
{% elsif count2 == true %}
{% assign count2 = false %}
{% elsif count3 == true %}
{% assign count3 = false %}
{% elsif count4 == true %}
{% assign count4 = false %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
</div>