Ayant des difficultés avec Jekyll / liquide
Question
Je suis Tring faire une boucle pour les liens Nav sous mes messages. Cela va dans le _layout de posts.html
Je ne peux pas obtenir le lien pour ne pas montrer si le poste est le dernier ou le premier. Toute aide serait génial.
{% for post in site.posts %} {% if post.previous != forloop.last %} ← Last {% elsif post.next != forloop.first %} Next → {% endif %} {% endfor %}
La solution
J'ai eu plus de chance en utilisant 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 %}
Autres conseils
Modifier vos relevés de if
juste vérifier si existe 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 %}
Ajoutez des images à l'arrière-plan de lien.
Pour les images à ajouter apparaissent juste image: [image location]
dans votre question avant YAML
<div class="postNav clearfix">
{% if page.previous.url %}
<a class="prev{% if page.previous.image %} image{% endif %}" href="{{ page.previous.url }}"><span>« {{ page.previous.title }}</span>
{% if page.previous.image %}
<img src="{{ '/assets/blog-img/' | append: page.previous.image }}" alt="">
{% endif %}
</a>
{% endif %}
{% if page.next.url %}
<a class="next{% if page.next.image %} image{% endif %}" href="{{ page.next.url }}"><span>{{ page.next.title }} »</span>
{% if page.next.image %}
<img src="{{ '/assets/blog-img/' | append: page.next.image }}" alt="">
{% endif %}
</a>
{% endif %}
</div>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow