限制 Jekyll 标签显示在主页上

问题描述 投票:0回答:1

我想在我的主页上显示最新博客文章中的最新标签(或将其限制为 6 个)。

到目前为止,我的代码显示了每个标签:

<div class="archive-tags">
    {% for post in site.posts %}
    {% if post.tags != empty %}
      {% for tag in post.tags %}
          <a href="{{site.baseurl}}/tags/#{{tag|slugify}}">{{ tag }}</a>
      {% endfor %}
    {% endif %}
    {% endfor %}
  </div>

我想知道使用什么标记来限制此操作或仅显示最新的博客文章标签。

感谢您的阅读!

tags jekyll liquid
1个回答
0
投票

我正在寻找的答案很简单,只需添加

limit: 1

修改后的工作代码现在是:

<div class="archive-tags">
{% for post in site.posts limit: 1 %}
{% if post.tags != empty %}
  {% for tag in post.tags %}
      <a href="{{site.baseurl}}/tags/#{{tag|slugify}}">{{ tag }}</a>
  {% endfor %}
{% endif %}
{% endfor %}
© www.soinside.com 2019 - 2024. All rights reserved.