【问题标题】:Jekyll blog posts on non index.html pages非 index.html 页面上的 Jekyll 博客文章
【发布时间】:2014-09-25 21:42:41
【问题描述】:

我使用 Jekyll 网站上的以下代码 sn-p 在我的 index.html 页面上对 Jekyll 博客文章进行分页:

<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: '//', '/' }}">&laquo; Prev</a>
  {% else %}
    <span>&laquo; 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 &raquo;</a>
  {% else %}
    <span>Next &raquo;</span>
  {% endif %}
</div>
{% endif %}

  </ul>

    </div>

但是,当我尝试将此添加到 /pages/Blog.html 页面时,它不起作用。它不显示我的 _posts 目录中的任何帖子,而是生成并清空容器。我假设这是一个路径问题。

我已根据需要将 YAML 标头添加到 Blog.html 文件中。当页面被渲染时,它会产生一个空容器。

【问题讨论】:

    标签: html jekyll liquid


    【解决方案1】:

    如果您想要一个看起来像 /pages/Blog/ 的 URL 用于您的帖子列表:

    1. 通过在_config.yml 中设置paginate: 5 来激活分页

    2. _config.yml中设置paginate_path: pages/Blog/page:num

    3. 将 /pages/Blog.html 重命名为 pages/Blog/index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      相关资源
      最近更新 更多