BLL*_*L27 8 html liquid jekyll
我使用了来自Jekyll网站的以下代码片段在我的index.html页面上对Jekyll plog帖子进行了分页:
<div class="container">
<ul class="post-list">
<!-- This loops through the paginated posts -->
{% for post in paginator.posts %}
<h1><a href="{{ post.url }}">{{ post.title }}</a></h1>
<p class="author">
<span class="date">{{ post.date }}</span>
</p>
<div class="content">
{{ post.content }}
</div>
{% endfor %}
{% if paginator.total_pages > 1 %}
<div class="pagination">
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">« Prev</a>
{% else %}
<span>« Prev</span>
{% endif %}
{% for page in (1..paginator.total_pages) %}
{% if page == paginator.page %}
<em>{{ page }}</em>
{% elsif page == 1 %}
<a href="{{ '/index.html' | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a>
{% else %}
<a href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a>
{% endif %}
{% endfor %}
{% if paginator.next_page %}
<a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Next »</a>
{% else %}
<span>Next »</span>
{% endif %}
</div>
{% endif %}
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将其添加到/pages/Blog.html页面时,它不起作用.它没有显示我的_posts目录中的任何帖子,而是生成并清空容器.我假设这是一个路径问题.
我已根据需要将YAML标头添加到Blog.html文件中.呈现页面时,它会生成一个空容器.
Dav*_*uel 15
如果您想要一个与/pages/Blog/您的帖子列表相似的网址:
通过设置paginate: 5in来激活分页_config.yml
设置paginate_path: pages/Blog/page:num在_config.yml
将/pages/Blog.html重命名为 pages/Blog/index.html
| 归档时间: |
|
| 查看次数: |
1870 次 |
| 最近记录: |