私はWordpressでTimber Pluginを使用しています。私は各カテゴリに4つの記事を表示するループを作成したいと思います。Timber Wordpress各カテゴリーの投稿を表示
publications.php
$context = Timber::get_context();
$post = new TimberPost();
$cat_id = wp_get_post_categories($post->ID);
$context['each_cat'] = Timber::get_posts(array('cat' => $cat_id[0], 'posts_per_page' => 4));
Timber::render(array('publications.twig', 'page.twig'), $context);
publications.twig
{% for category in each_cat %}
<h2 class="title">{{category.name}}</h2>
<article class="article--box">
{% include "bloc_preview.twig" %}
</article>
{% endfor %}
ザはbloc_preview.twig
を含む各ポストのプレビューです。
ありがとうございます。何も表示されません。どうしてか分かりません – Jandon