如何使用 Jekyll 的分页工具对 _posts 中的子目录进行排序

How to use Jekyll's pagination tool to sort through a subdirectory within _posts

在使用 liquid markdown 的 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>

我试图检索类别为 'Blog' 的帖子,但是当我 运行 它时,它分页到我想要的每页 7 篇文章,但有些页面的文章少于 7 篇或根本没有文章出现。

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

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

谢谢!

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