0

すべての Jekyll 投稿を時系列で一覧表示したいのですが、同じカテゴリのすべての投稿には、私が付けたのと同じクラス名が付けられます (例: cate1cate2cate3...)。私は多くの方法で試しましたが、まだこれを理解できません。助けてください。

たとえば、次のコードはすべての投稿を時系列で一覧表示できますが、すべてのリンクは同じcate1クラスになります。

{% for post in site.posts %}
  {% if site.categories.CATEGORY1 %}
    <a class="cate1" href="{{ post.url }}">{{ post.title }}</a>
  {% elsif site.categories.CATEGORY2 %}
    <a class="cate2" href="{{ post.url }}">{{ post.title }}</a>
  {% elsif site.categories.CATEGORY3 %}
    <a class="cate3" href="{{ post.url }}">{{ post.title }}</a>
  {% endif %}
{% endfor %}

私も試しました:

{% for post in site.posts %}
  {% for post in site.categories.CATEGORY1 %}
    <a class="cate1" href="{{ post.url }}">{{ post.title }}</a>
  {% endfor %}
  {% for post in site.categories.CATEGORY2 %}
    <a class="cate2" href="{{ post.url }}">{{ post.title }}</a>
  {% endfor %}
  {% for post in site.categories.CATEGORY3 %}
    <a class="cate3" href="{{ post.url }}">{{ post.title }}</a>
  {% endfor %}
{% endfor %}

これにより、各リンクが 13 回生成されます。これは、投稿の合計量です。リンクの順序は、時系列順ではなく、ループ内のカテゴリの順序に基づいています。

私も試しました:

{% for post in site.posts %}
  {% for CATEGORY1 in site.categories %}
    <a class="cate1" href="{{ post.url }}">{{ post.title }}</a>
  {% endfor %}
  {% for CATEGORY2 in site.categories %}
    <a class="cate2" href="{{ post.url }}">{{ post.title }}</a>
  {% endfor %}
  {% for CATEGORY3 in site.categories %}
    <a class="cate3" href="{{ post.url }}">{{ post.title }}</a>
  {% endfor %}
{% endfor %}

これにより、各リンクが 25 回生成されます。これは、5 つのカテゴリと 5*5=25 があるためだと思います。各リンクには異なるクラス名があります (例: 、a_CATEGORY1_post.cate1) 。ただし、すべての投稿は時系列順です。a_CATEGORY1_post.cate2a_CATEGORY1_post.cate3

4

1 に答える 1