在 Jekyll 的主页中列出 Collections/Posts 带有自己的标签
Listing Collections/Posts with own Tags in Homepage at Jekyll
在 Jekyll 中,我目前可以在主页上列出 collections/posts,但标签不显示。
对于这项工作,我尝试使用半自定义循环,但它没有像下面的示例代码那样列出标签,并期望显示 collections/posts 带有标签,但它没有。
{% assign ordered_works = site.works | sort:"work-order" %}
{% for work in ordered_works reversed limit: 3 %}
<div class="scene">
<div class="featured-works__item featured-works__item--blue tween-animation">
<picture class="featured-works__item-thumb">
<source
media="(min-width: 768px)"
srcset="/assets/images/works/{{ work.thumb-image }}.png 1x, /assets/images/works/{{ work.thumb-image }}@2x.png 2x"
>
<source
media="(max-width: 767px)"
srcset="/assets/images/works/{{ work.mobile-thumb-image }}.png 1x"
>
<img
src="/assets/images/works/{{ work.thumb-image }}.png"
alt="{% if work.cover-image-alt-text != "" %}{{work.cover-image-alt-text}}{% else %}{{ work.title}}{% endif %}"
/>
</picture>
<figure>
</figure>
<div class="featured-works__item-info" {% if work.bg-color %}style="background-color: {{ work.bg-color }}" {% endif %}>
<h4>{{ work.title }}</h4>
<h5>{{ work.sub-title }}</h5>
<ul>
{% for tag in page.tags %}
<li>#{{ tag }}</li>
{% endfor %}
</ul>
<p>{{ work.summary }}</p>
<a href="{{ work.url }}" class="primary-button">Click Here to Detail</a>
</div>
</div>
</div>
{% endfor %}
您可以将 {% for tag in page.tags %}
替换为 {% for tag in work.tags %}
。
在 Jekyll 中,我目前可以在主页上列出 collections/posts,但标签不显示。
对于这项工作,我尝试使用半自定义循环,但它没有像下面的示例代码那样列出标签,并期望显示 collections/posts 带有标签,但它没有。
{% assign ordered_works = site.works | sort:"work-order" %}
{% for work in ordered_works reversed limit: 3 %}
<div class="scene">
<div class="featured-works__item featured-works__item--blue tween-animation">
<picture class="featured-works__item-thumb">
<source
media="(min-width: 768px)"
srcset="/assets/images/works/{{ work.thumb-image }}.png 1x, /assets/images/works/{{ work.thumb-image }}@2x.png 2x"
>
<source
media="(max-width: 767px)"
srcset="/assets/images/works/{{ work.mobile-thumb-image }}.png 1x"
>
<img
src="/assets/images/works/{{ work.thumb-image }}.png"
alt="{% if work.cover-image-alt-text != "" %}{{work.cover-image-alt-text}}{% else %}{{ work.title}}{% endif %}"
/>
</picture>
<figure>
</figure>
<div class="featured-works__item-info" {% if work.bg-color %}style="background-color: {{ work.bg-color }}" {% endif %}>
<h4>{{ work.title }}</h4>
<h5>{{ work.sub-title }}</h5>
<ul>
{% for tag in page.tags %}
<li>#{{ tag }}</li>
{% endfor %}
</ul>
<p>{{ work.summary }}</p>
<a href="{{ work.url }}" class="primary-button">Click Here to Detail</a>
</div>
</div>
</div>
{% endfor %}
您可以将 {% for tag in page.tags %}
替换为 {% for tag in work.tags %}
。