2010-01-08 14 views
11

Estoy haciendo un bucle para enlaces de navegación debajo de mis publicaciones. Esto entra en el _layout de posts.htmlTiene dificultades con Jekyll/Liquid

No puedo obtener el enlace para no mostrar si la publicación es la última o la primera. Cualquier ayuda sería increíble.

 
{% for post in site.posts %} 

    {% if post.previous != forloop.last %} 
     ← Last 
    {% elsif post.next != forloop.first %} 
     Next → 
    {% endif %} 

{% endfor %} 

Respuesta

21

tuve mejor suerte usando page.next/previous

{% if page.previous %} 
     <a rel="prev" href="{{ page.previous.url }}">&larr; Older</a> 
    {% endif %} 
    {% if page.next %} 
     <a rel="next" href="{{ page.next.url }}">Newer &rarr;</a> 
    {% endif %} 
1

Cambiar los if declaraciones sólo compruebe si existe post.previous.

{% if post.previous %} 
<span class="page-nav-item"> 
    <a rel="prev" href="{{ post.previous.url }}" title="View {{ post.previous.title }}">&larr; 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 &rarr;</a> 
</span> 
{% endif %} 
+0

tuve mejor suerte usando 'page.next' y 'page.previous', pero gracias por la ayuda. –

0

Añadir imágenes a su fondo de enlace. Para las imágenes aparezcan sólo tiene que añadir image: [image location] en su parte delantera YAML cuestión

<div class="postNav clearfix"> 
    {% if page.previous.url %} 
     <a class="prev{% if page.previous.image %} image{% endif %}" href="{{ page.previous.url }}"><span>&laquo;&nbsp;{{ 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 }}&nbsp;&raquo;</span> 
     {% if page.next.image %} 
     <img src="{{ '/assets/blog-img/' | append: page.next.image }}" alt=""> 
     {% endif %} 
     </a> 
     {% endif %} 
</div> 
Cuestiones relacionadas