私はExpressionEngineのCraftを初めて使い、月/年のアーカイブページをどのように処理するのか疑問に思っています。私はアーカイブを表示する方法を考え出しましたが、コードはあまりにも複雑です。より簡単なアプローチがあるのか、またはすべてを表示するニュース/インデックスと同じテンプレートを使用してアーカイブを表示することができるかどうかは疑問でした。
EEでは、これは可能であり、それがCraftにあったかどうか疑問に思っていました。
前もって感謝します。下の私のアーカイブテンプレートコード。
{% if month is not defined %}
{% set before = year + 1 %}
{% set after = year %}
{% else %}
{% if month == 12 %}
{% set yearBefore = year + 1 %}
{% set monthBefore = '01' %}
{% set before = yearBefore~'-'~monthBefore %}
{% set after = year~'-'~month %}
{% else %}
{% set before = year ~ '-' ~ (month + 1) %}
{% set after = year ~ '-' ~ month %}
{% endif %}
{% endif %}
{% set allEntries = craft.entries.section('news').limit(null).after(after).before(before) %}
{% for date, entries in allEntries | group("postDate|date('F Y')") %}
Entries from {{ date }}
{% for entry in entries %}
{% for asset in entry.newsthumb %}
<div class="image-wrapp">
</div> {% endfor %} <div
class="text-wrapp">
{{ entry.title
}}
}}
{{ entry.newssummary }}
{% if entry.newscategory | length %}
- {% endif %} {% nav category in
{{ category.title }}{{
not loop.last ? ', ' }}
entry.newscategory %}
{% endnav %} {% if entry.newscategory | length %}
{% endif %} </div>
{% endfor %} {% endfor %}
ベストアンサー
私がこれを行う方法は、各エントリのセットごとに異なるテンプレートを使用することです。したがって、特定の月のすべての記事(
_news/index-archive
)と、カテゴリ内のすべての記事のカテゴリー1のアーカイブ記事があります。 _news/index-category
_news/index-all
、おそらくタグによる記事の場合などです。
これらの各テンプレートは、 entries
を関連するエントリに設定してから行います
{% include '_news/index-generic' with {
entries: entries
} only %}
また、 index-generic
にはすべての共有表示コードがあります。
おそらく、他にもいくつか変化するものがあります。例えば、見出し:
{% include '_news/index-generic' with {
entries: entries,
heading: 'Category: '~category.title
} only %}