html - Jekyll every 4th item in loop display differently -
i using jekyll populate blog page blog posts. want there 2 posts every div
"row" class, want every 4th item ad (skip on post , move next row still include else that's not post).
so if there 6 posts, output should this
<div class="row"> <!-- 1st row --> <div> {{ post.title }} </div> <!-- 1st post, no skip --> <div> {{ post.title }} </div> <!-- 2nd post, no skip --> </div> <div class="row"> <!-- 2nd row --> <div> {{ post.title }} </div> <!-- 3rd post, no skip --> <div> not post </div> <!-- skip post 4, put else --> </div> <div class="row"> <!-- 3rd row --> <div> {{ post.title }} </div> <!-- 4th post, because last item skipped display else --> <div> {{ post.title }} </div> <!-- 5th post, no skip --> </div> <div class="row"> <!-- 4th row --> <div> {{ post.title }} </div> <!-- 6th post, no skip --> </div> <!-- , on, every 4th item not post, posts continue after skipped post -->
i have post loop part cant figure out how add skip
{% assign rows = site.posts.size | divided_by: 2.0 | ceil %} {% in (1..rows) %} {% assign offset = forloop.index0 | times: 2 %} <div class="row blogitems"> {% post in site.posts limit:2 offset:offset %} <div class="col-md-6"> <p>{{ post.title }}</p> </div> {% endfor %} </div> {% endfor %}
i think can walk through items while checking modulo. this:
<div class="row blogitems"> {% post in site.posts %} {% assign mod3 = forloop.index | modulo: 3 %} <div class="col-md-6"><p>{{ post.title }}</p></div> {% if mod3 == 0 %}<div class="col-md-6"><p>this not post</p>{% endif %} {% if mod3 == 0 or mod3 == 2 %}</div><div class="row blogitems">{% endif %} {% endfor %} </div>
Comments
Post a Comment