【问题标题】:Cannot get paganation using jekyll-paginate-v2 to work无法使用 jekyll-paginate-v2 进行分页工作
【发布时间】:2019-11-03 13:15:32
【问题描述】:

我一直在查看有关堆栈溢出和其他来源的类似问题的多个答案,但根本无法解决我的问题。

我有一个由index.md 组成的页面,其中包含以下主要内容:

# Feel free to add content and custom Front Matter to this file.
# To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults

title: title
layout: default
pagination: 
  enabled: true
---

这就是我列出我的帖子的方法:

    <!-- 
        Here is the main paginator logic called.
        All calls to site.posts should be replaced by paginator.posts 
    -->
    {% for post in paginator.posts %}
      <li>
        <span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>

        <h2>
          <a class="post-link" href="{{ post.url | relative_url }}">{{ post.title | escape }}</a>
        </h2>
      </li>
    {% endfor %}
  </ul>

  <!-- 
    Showing buttons to move to the next and to the previous list of posts (pager buttons).
  -->
  {% if paginator.total_pages > 1 %}
  <ul class="pager">
      {% if paginator.previous_page %}
      <li class="previous">
          <a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&larr; Newer Posts</a>
      </li>
      {% endif %}
      {% if paginator.next_page %}
      <li class="next">
          <a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Older Posts &rarr;</a>
      </li>
      {% endif %}
  </ul>
  {% endif %}


<div class="pagination">
  {% if paginator.previous_page %}
    <a href="{{ paginator.previous_page_path }}" class="previous">
      Previous
    </a>
  {% else %}
    <span class="previous">Previous</span>
  {% 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>
  {% else %}
    <span class="next ">Next</span>
  {% endif %}
</div>

我已将 gem 添加到插件列表和 gem 文件中并运行 bundle install,我的配置如下所示:

pagination:
  enabled: true
  per_page: 3
  offset: 2
  permalink: '/page/:num/'
  title: ':title - page :num of :max'
  limit: 0
  sort_field: 'date'
  sort_reverse: true

但是,当我运行 bundle exec jekyll s 时,我的测试帖子未列出。 但如果我使用:

{% for post in site.posts%}
{{post.title}}
{% endfor %}

我的测试帖子按我的意图列出。任何可以帮助我解决我做错了什么的人,我根本无法发现它。

【问题讨论】:

    标签: jekyll jekyll-paginator


    【解决方案1】:

    您是否有特定原因将offset: 2 包含在_config.yml 中?这将排除前 2 个帖子出现在分页中,因此如果您的项目中没有至少 3 个帖子,则不会显示任何内容。

    尝试从配置文件中删除偏移线,重新运行bundle exec jekyll serve,看看功能是否有效。

    有关偏移使用情况,请查看jekyll-paginate-v2 README“偏移帖子”部分。

    【讨论】:

    • 该死,谢谢!我完全错过了,非常感谢你
    猜你喜欢
    • 1970-01-01
    • 2020-11-29
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2022-10-03
    • 1970-01-01
    相关资源
    最近更新 更多