在jekyll中,category.html如何使用分页为特定类别的帖子编写逻辑? [英] how in jekyll, for categories.html write a logic for posts in specific category using pagination?
问题描述
我有具有post.thumb且没有post.thumb的帖子,并且我只想在下面的结构中显示具有post.thumb的帖子,而不对帖子使用限制和偏移.
I have posts with post.thumb and without post.thumb, and i want to show only posts with post.thumb in structure below without using limit and offset for posts.
我有一个具有以下结构的category.html:
I have a categories.html with next structure:
<section class="type-one">
{% for post in pagination.posts limit:1 Offset:0 %}
<div class="col-md-7">
{% include FirstPostInCategoryNews.html %}
</div>
{% endfor %}
<div class="col-md-5 two_items_incide">
{% for post in pagination.posts limit:2 Offset:1 %}
{% include TwoPostsAfterFirstPostInCatNews.html%}
{% endfor %}
</div>
</section>
<section class="others_posts_in_cat_news">
<div class="col-md-7">
{% for post in pagination.posts limit:7 Offset:3 %}
{% include OtherPostsInCategoryNews.html %}
{% endfor %}
</div>
</section>
for better understanding what i want is something like this
推荐答案
here is my solution that works, with help of JoostS
首先我添加到所有帖子中,其中有post.thumb下一个标签(bg)
first of all I added to all my posts wich has post.thumb next tag (bg)
---
layout: post
thumb: "path/to/image/"
bg: "yes"
---
下一步是我使用过滤器遍历所有带有bg:是"的帖子.
the next step is that I loop through all my posts with bg: "yes", by using filters.
最后在这里我做了什么:
so finaly here what i did:
<section class="type-one">
<div class="row">
{% assign posts = paginator.posts | where: "bg", "yes" %} // creating var//
<div class="col-md-7">
{% for post in posts limit: 1 %}
{% include FirstPostInCategoryNews.html %}
{% endfor %}
</div>
<div class="col-md-5 item-title-white">
{% for post in posts limit: 2 offset: 1 %}
{% include TwoPostsAfterFirstPostInCatNews.html %}
{% endfor %}
</div>
</div>
</section>
第二部分:
<section class="others_posts_in_cat_news">
<div class="col-md-7">
{% assign posts = paginator.posts | where: "bg", "yes" %}
{% for post in posts limit: 4 offset: 3 %}
{% include OtherPostsInCategoryNews.html %}
{% endfor %}
</div>
</section>
如果某人不了解某些内容,请随时提问!
if sombody didnt understand something, feel free to ask!
这篇关于在jekyll中,category.html如何使用分页为特定类别的帖子编写逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!