Tendo dificuldades com jekyll / líquido
Pergunta
Estou tentando fazer um loop para links de navegação abaixo das minhas postagens. Isso está entrando na realização de posts.html
Não consigo obter o link para não mostrar se a postagem for a última ou a primeira. Qualquer ajuda seria incrível.
{% for post in site.posts %} {% if post.previous != forloop.last %} ← Last {% elsif post.next != forloop.first %} Next → {% endif %} {% endfor %}
Solução
Tive mais sorte usando página.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 %}
Outras dicas
Mudar seu if
declarações para apenas verificar se post.previous
existe.
{% 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 %}
Adicione imagens ao seu plano de fundo do link. Para imagens para aparecer, apenas adicione image: [image location]
em seu assunto da frente 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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow