如何对已排序的Jekyll集合进行分页?

如何对已排序的Jekyll集合进行分页?,jekyll,liquid,Jekyll,Liquid,我正在尝试创建左/右箭头链接,以导航到集合中的上一页/下一页。这对于标准集合很容易实现: {% if page.previous %} <a href="{{ page.previous.url }}>Left arrow</a> {% endif %} {% if page.next %} <a href="{{ page.next.url }}>Right arrow</a> {% endif %} 我是否在我的流畅语法中遗漏了什么,

我正在尝试创建左/右箭头链接,以导航到集合中的上一页/下一页。这对于标准集合很容易实现:

{% if page.previous %}
  <a href="{{ page.previous.url }}>Left arrow</a>
{% endif %}
{% if page.next %}
  <a href="{{ page.next.url }}>Right arrow</a>
{% endif %}
我是否在我的流畅语法中遗漏了什么,或者我的逻辑完全走错了方向


我目前的黑客解决方案是在文档文件名前面加上数字,以确保默认情况下它们的顺序正确。但是,当我移交网站时,这将不起作用,因为我无法信任非技术性内容创建者来保持文件名的有序。

我刚刚找到并测试了解决方案,它可以工作!我认为关键在于捕获集合名称并将其作为字符串分配给变量


有没有人有更好的/不太详细的方法来做这件事?

我刚刚找到并测试了解决方案,它很有效!我认为关键在于捕获集合名称并将其作为字符串分配给变量


有没有人有更好的/不太详细的方法来做这件事?

您链接的技术几乎就是我在本系列的下一个/上一个中使用的技术。如果链接过时,下面是一个类似的片段,用于保存集合项对象,而不仅仅是URL:

{% if page.collection %}
  {% assign collection = site[page.collection] | sort: 'position' %}
  {% assign prev = collection | last %}
  {% assign next = collection | first %}

  {% for item in collection %}
    {% if item.title == page.title %}
      {% unless forloop.first %}
        {% assign prev = iterator %}
      {% endunless %}

      {% unless forloop.last %}
        {% assign next = collection[forloop.index] %}
      {% endunless %}
    {% endif %}

    {% assign iterator = item %}
  {% endfor %}
{% endif %}

{% if prev %}
  <a href="{{ prev.url }}">{{ prev.title }}</a>
{% endif %}

{% if next %}
  <a href="{{ next.url }}">{{ next.title }}</a>
{% endif %}
{%if page.collection%}
{%assign collection=site[page.collection]| sort:'位置'%}
{%assign prev=collection | last%}
{%assign next=集合| first%}
{集合%中的项的%s}
{%if item.title==page.title%}
{%forloop.first%}
{%assign prev=迭代器%}
{%end除非%}
{%forloop.last%}
{%assign next=集合[forloop.index]}
{%end除非%}
{%endif%}
{%assign iterator=item%}
{%endfor%}
{%endif%}
{%if-prev%}
{%endif%}
{%if next%}
{%endif%}

您链接的技术与我在本系列的下一个/上一个中使用的技术非常相似。如果链接过时,下面是一个类似的片段,用于保存集合项对象,而不仅仅是URL:

{% if page.collection %}
  {% assign collection = site[page.collection] | sort: 'position' %}
  {% assign prev = collection | last %}
  {% assign next = collection | first %}

  {% for item in collection %}
    {% if item.title == page.title %}
      {% unless forloop.first %}
        {% assign prev = iterator %}
      {% endunless %}

      {% unless forloop.last %}
        {% assign next = collection[forloop.index] %}
      {% endunless %}
    {% endif %}

    {% assign iterator = item %}
  {% endfor %}
{% endif %}

{% if prev %}
  <a href="{{ prev.url }}">{{ prev.title }}</a>
{% endif %}

{% if next %}
  <a href="{{ next.url }}">{{ next.title }}</a>
{% endif %}
{%if page.collection%}
{%assign collection=site[page.collection]| sort:'位置'%}
{%assign prev=collection | last%}
{%assign next=集合| first%}
{集合%中的项的%s}
{%if item.title==page.title%}
{%forloop.first%}
{%assign prev=迭代器%}
{%end除非%}
{%forloop.last%}
{%assign next=集合[forloop.index]}
{%end除非%}
{%endif%}
{%assign iterator=item%}
{%endfor%}
{%endif%}
{%if-prev%}
{%endif%}
{%if next%}
{%endif%}