问题
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.
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
回答1:
here is my solution that works, with help of JoostS
first of all I added to all my posts wich has post.thumb next tag (bg)
---
layout: post
thumb: "path/to/image/"
bg: "yes"
---
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>
2nd part:
<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!
来源:https://stackoverflow.com/questions/53048638/how-in-jekyll-for-categories-html-write-a-logic-for-posts-in-specific-category