【问题标题】:how in jekyll, for categories.html write a logic for posts in specific category using pagination?在 jekyll 中,对于 categories.html,如何使用分页为特定类别的帖子编写逻辑?
【发布时间】:2018-10-29 15:19:35
【问题描述】:

我有 post.thumb 和没有 post.thumb 的帖子,我只想在下面的结构中显示带有 post.thumb 的帖子,而不使用帖子的限制和偏移量。

我有一个带有下一个结构的 categories.html:

       <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>

为了更好地理解我想要的是this

【问题讨论】:

  • 我认为您的帖子需要一个“位置”过滤器,例如:stackoverflow.com/q/24701557/2397550
  • 我怎样才能为 paginator.posts 中的帖子的 {% 编写正确的过滤器 |其中:“拇指”、“以图片/新闻开头......”%}

标签: html loops pagination jekyll liquid


【解决方案1】:

JoostS 的帮助下,这是我的解决方案

首先我添加到我的所有帖子中都有 post.thumb 下一个标签 (bg)

---
layout: post
thumb: "path/to/image/"
bg: "yes"
---

下一步是使用过滤器循环浏览所有带有 bg: "yes" 的帖子。

所以最后我做了什么:

<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>

如果有人不明白,请随时提问!

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    相关资源
    最近更新 更多