我的基于Jekyll的投资组合目前按时间顺序列出项目.我正在使用page.previous并page.next显示我的投资组合中的下一个和上一个帖子.当没有"前一个"或"下一个"项目时,就会有一个巨大的空白空间.
我该如何修改:
<section id="more-work">
{% if page.previous %}
<div class="left">
<a class="equalize" href="{{page.previous.url}}" title="Previous Post: {{page.previous.title}}">
<div>
<h6> ? Previous Project </h6>
<h4> {{page.previous.title}} </h4>
</div>
</a>
</div>
{% endif %} {% if page.next %}
<div class="right">
<a class="equalize" href="{{page.next.url}}" title="next Post: {{page.next.title}}">
<div>
<h6> Next Project ?</h6>
<h4> {{page.next.title}}</h4>
</div>
</a>
</div>
{% endif %}
</section>
Run Code Online (Sandbox Code Playgroud)
...所以它循环到列表的末尾或列表的开头?
这可以做到这一点:
<section id="more-work">
{% if page.previous %}
{% assign previous = page.previous %}
{% else %}
{% assign previous = site.posts[0] %}
{% endif %}
<div class="left">
<a class="equalize" href="{{site.baseurl}}{{previous.url}}" title="Previous Post: {{previous.title}}">
<div>
<h6> ? Previous Project </h6>
<h4> {{previous.title}} </h4>
</div>
</a>
</div>
{% if page.next %}
{% assign next = page.next %}
{% else %}
{%comment%}
As the array index start at zero we substract 1 to the total count,
we then get the last post index in the site.posts array
{%endcomment%}
{% assign last lastPostIndex = site.posts | size | minus: 1 %}
{% assign next = site.posts[lastPostIndex] %}
{% endif %}
<div class="right">
<a class="equalize" href="{{site.baseurl}}{{next.url}}" title="next Post: {{next.title}}">
<div>
<h6> Next Project ?</h6>
<h4> {{next.title}}</h4>
</div>
</a>
</div>
</section>
Run Code Online (Sandbox Code Playgroud)