【问题标题】:How to use Jekyll's pagination tool to sort through a subdirectory within _posts如何使用 Jekyll 的分页工具对 _posts 中的子目录进行排序
【发布时间】:2015-10-16 21:51:09
【问题描述】:

在 Jekyll 中使用液体降价使分页无法正常工作。

使用了分页器功能,帖子会分页,但我正在尝试找出一种方法来过滤掉分页内容。

在我的 _posts 目录中,我有一个 blog 子目录和一个 news 子目录。我试图只对博客中的文章而不是新闻进行分页。

{% assign posts = site.posts | where: 'category','Blog' %}
<ul class="list-unstyled blog-list">

  <!-- This loops through the paginated posts -->
  {% for post in paginator.posts %}
    {% assign posts = site.posts | where: 'category','Blog' %}
    {% if post.category == 'Blog' %}

Do Stuff

    {% endif %}
  {% endfor %}
  <!-- Pagination links -->
  <div class="pagination">
    {% if paginator.previous_page == 1 %}
      <a href="{{ paginator.previous_page_path }}" class="previous">Previous</a>
    {% endif %}
    {% if paginator.previous_page > 1%}
      <a href="{{ paginator.previous_page_path }}" class="previous">Previous</a>
    {% endif %}
    <span class="page_number ">Page: {{ paginator.page }} of {{ paginator.total_pages }}</span>

    {% if paginator.next_page   %}
      <a href="{{ paginator.next_page_path }}" class="next">Next</a>

    {% endif %}
  </div>
</ul>

我试图检索具有“博客”类别的帖子,但是当我运行它时,它会分页到我想要的每页 7 篇文章,但有些页面的文章少于 7 篇,或者根本没有文章显示。

我认为我的循环逻辑有问题,但我不确定是什么。

也许它抓取了 _posts 中的所有文章,但不显示页面上的新闻文章?

谢谢!

【问题讨论】:

    标签: for-loop pagination jekyll liquid


    【解决方案1】:

    Jekyll Paginate 没有过滤功能,因此无法按类别过滤分页帖子。我建议您查看提供该功能的Octopress Paginate 插件。

    【讨论】:

      猜你喜欢
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 2022-10-03
      • 2014-12-06
      相关资源
      最近更新 更多