質問

私は私の記事下のナビゲーションリンクのループを行うためにトリングです。これはposts.html

の_layoutに起こっています

私はポストが最後または最初のであれば表示しないようにリンクを取得することはできません。すべてのヘルプは素晴らしいだろう。

{% 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 }}">&larr; Older</a>
    {% endif %}
    {% if page.next %} 
        <a rel="next" href="{{ page.next.url }}">Newer &rarr;</a>
    {% endif %}

他のヒント

ifが存在するかどうかだけをチェックしてください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 %}

あなたのリンクの背景に画像を追加します。  画像を表示するためには、ちょうどあなたのYAMLのフロント問題でimage: [image location]を追加します。

<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> 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top