Я - Тринг, чтобы сделать цикл для Военно-морских ссылок ниже мои сообщения. Это входит в _layout posts.html
Я не могу заставить ссылку не показывать, является ли сообщение последним или первым. Любая справка была бы потрясающей.
{% for post in site.posts %} {% if post.previous != forloop.last %} ← Last {% elsif post.next != forloop.first %} Next → {% endif %} {% endfor %}
Мне посчастливилось использовать page.next/previous
{% if page.previous %}
<a rel="prev" href="{{ page.previous.url }}">← Older</a>
{% endif %}
{% if page.next %}
<a rel="next" href="{{ page.next.url }}">Newer →</a>
{% endif %}
Измените ваши утверждения , если
, чтобы просто проверить, существует ли post.previous
.
{% if post.previous %}
<span class="page-nav-item">
<a rel="prev" href="{{ post.previous.url }}" title="View {{ post.previous.title }}">← View previous article</a>
</span>
{% endif %}
{% if post.next %}
<span class="page-nav-item">
<a rel="next" href="{{ post.next.url }}" title="View {{ post.next.title }}">View next article →</a>
</span>
{% endif %}