在堆栈溢出和其他来源中,我一直在寻找类似问题的多个答案,但根本无法解决我的问题。
我有一个由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: '//', '/' }}">← Newer Posts</a>
</li>
{% endif %}
{% if paginator.next_page %}
<li class="next">
<a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Older Posts →</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文件中并运行捆绑安装,我的配置如下所示:
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 %}
我的测试帖子被列为我的意图。任何可以帮助我解决我做错事情的人,我都无法发现。
答案 0 :(得分:1)
您是否有特定原因将offset: 2
包含在_config.yml
中?这会将前2个帖子排除在分页中,因此,如果您的项目中至少没有3个帖子,则不会显示任何内容。
尝试从配置文件中删除偏移线,重新运行bundle exec jekyll serve
,然后查看该功能是否有效。
有关偏移量的使用,请检查jekyll-paginate-v2 README部分的“偏移量”。