0

テンプレートでコンテンツをレンダリングするために液体 (https://github.com/tobi/liquid/) を使用しています。ホームページに「最近のアクティビティ」セクションを設けて、日付順に 3 つの異なるコンテンツ タイプの最新の更新情報を検索します (最大 4 つまで)。

このようなことは液体で可能ですか?

したがって、平易な言葉では、クエリは次のようになります..「content_type_1、2、または3から日付順に並べられた4つの最新アイテムを選択してください」

ありがとう、マーク。

4

1 に答える 1

1

content_typeとは、投稿のカテゴリを意味すると思います。追加することで投稿を分類できます

category: type_1

投稿のYAMLFrontMatterに移動するか、その投稿をtype_1/_postsフォルダーに入れます。これができたら、これがあなたがやりたいことをするための少し厄介な方法です:

<div>
  {% assign count1 = true %}
  {% assign count2 = true %}
  {% assign count3 = true %}
  {% assign count4 = true %}
  {% for post in site.posts %}
     {% if post.categories contains 'type_1' or post.categories contains 'type_2' or ... %}
        {% if count1 == true or count2 == true or count3 == true or count4 == true %}
           <li><span>{{ post.date | date_to_string }}</span> &raquo; <a href="{{ post.url }}">{{ post.title }}</a></li>
           {% if count1 == true %}
              {% assign count1 = false %}
           {% elsif count2 == true %}
              {% assign count2 = false %}
           {% elsif count3 == true %}
              {% assign count3 = false %}
           {% elsif count4 == true %}
              {% assign count4 = false %}
           {% endif %}
        {% endif %}
     {% endif %}
  {% endfor %}
</div>
于 2011-07-24T21:53:55.043 に答える