【问题标题】:Take 3 posts at a time in Liquid (Jekyll)在 Liquid (Jekyll) 中一次发表 3 个帖子
【发布时间】:2016-12-31 02:00:43
【问题描述】:

这可能非常明显,但我正在从头开始制作 Jekyll 博客,并且我使用的是 Shopify 的 Liquid

假设我有一组帖子:

post1, post2, post3, post4, post5, post6, post7, post8, post9, post10

我正在尝试一次将三个帖子呈现为<div>。所以它看起来像这样:

<div>
    post1
    post2
    post3
</div>
<div>
    post4
    post5
    post6
</div>
<div>
    post7
    post8
    post9
</div>
<div>
    post10
</div>

我将如何在 Liquid 中实现这一点? 像 ruby​​ 的 splice 这样的东西似乎就足够了,但我在 Liquid 中找不到如何做到这一点。

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:
    {% for p in site.posts %}
       {% assign counter = forloop.index | modulo:3 %}
       {% if counter == 1 %}<div>{% endif %}
       <h3>{{ p.title }}</h3>
       {% if forloop.last or counter == 0 %}</div>{% endif %}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2015-07-24
      • 2016-12-22
      • 2015-11-09
      • 1970-01-01
      相关资源
      最近更新 更多