I use Timber plugin with Wordpress. I would like to create a loop which display 4 articles in each category.
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 %}
The include bloc_preview.twig is a preview of each post.