سؤال

أنا اتجه إلى حلقة لبطاقات NAV أسفل مشاركاتي. هذا هو ذاهب إلى _layout من المشاركات

لا أستطيع الحصول على الرابط لعدم إظهار ما إذا كان المنشور هو آخر أو الأول. أي مساعدة سيكون رائعا.

{٪ للنشر في الموقع. Posts٪} {٪ إذا post.previous! = forloop.last٪} ← أخيرة {٪ elsif post.next! = forloop.first٪} التالي → {٪ ENDIF٪} {٪ Endfor٪}
هل كانت مفيدة؟

المحلول

كان لدي حظ أفضل باستخدام الصفحة.

    {% 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 %}

إضافة صور إلى خلفية الرابط الخاصة بك. للصور لإظهار إضافة فقط image: [image location] في المسألة الأمامية YAML

<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