【问题标题】:Having difficulties with Jekyll / LiquidJekyll / Liquid 遇到困难
【发布时间】:2011-01-02 19:38:45
【问题描述】:

我正在尝试为我的帖子下方的导航链接做一个循环。这是进入posts.html的_layout

如果帖子是最后一个还是第一个,我无法获得不显示链接。任何帮助都会很棒。

{% for post in site.posts %} {% if post.previous != forloop.last %} ← 最后 {% elsif post.next != forloop.first %} 下一个 → {% 万一 %} {% endfor %}

【问题讨论】:

    标签: liquid jekyll


    【解决方案1】:

    我在使用 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 %}
    

    【讨论】:

      【解决方案2】:

      更改您的 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 %}
      

      【讨论】:

      • 我在使用 'page.next' 和 'page.previous' 时运气更好,但感谢您的帮助。
      【解决方案3】:

      将图像添加到您的链接背景。 要显示图像,只需在您的 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> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-25
        • 2013-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-11
        相关资源
        最近更新 更多