代码之家  ›  专栏  ›  技术社区  ›  ulima2_

Jekyll截断博客帖子数量的条件是排除一些

  •  1
  • ulima2_  · 技术社区  · 8 年前

    然而,我也分配了一个标记 exclude 我的一些博客帖子和那些我不想展示的帖子。这是可行的,但我没有得到最后10篇博客帖子,而是10减去 排除

    这看起来是这样的:

    ---
    layout: page
    title: "Last posts"
    permalink: /last/
    ---
    
    ### Last posts
    
    {% for post in site.posts limit:10 %}
        {% unless post.category == "exclude"%}
          * {{ post.date | date_to_string }} » [ {{ post.title }} ]({{ post.url }})
        {% endunless %}
    {% endfor %}
    

    如何始终显示最后10个非- 排除

    1 回复  |  直到 8 年前
        1
  •  1
  •   marcanuy    8 年前

    1. 创建一个包含不包含 exclude 标签

      {% assign nonexcludeposts = ''|split:''%}
      {% for post in site.posts %}
          {% unless post.category == "exclude"%}
          {% assign nonexcludeposts = nonexcludeposts|push:post%}
          {% endunless %}
      {% endfor %}
      
    2. <ul>
      {% for post in nonexcludeposts limit:10 %}
            <li>
            <a href="{{post.url|absolute_url}}">{{post.title}}</a>
            </li>
      {% endfor %}
      </ul>
      
    推荐文章