0
votes

I would like to render this loop in Timber. Can I have some help please ?

$query = get_posts(array('post_type' => 'lexique','posts_per_page' => -1));

$by_letter = array();
while( $query->have_posts() ) { $query->the_post();
  global $post;
  $letter = substr($post->post_name, 0, 1);
  if ( ! isset($by_letter[$letter]) ) $by_letter[$letter] = array();
  $by_letter[$letter][] = $post;
}
wp_reset_postdata();

So attach this loop with timber

$context = Timber::get_context();
Timber::render('lexique.twig', $context);

But I don't have any idea to do this.

1

1 Answers

-1
votes
$context = Timber::get_context();
$context['post'] = new TimberPost();
Timber::render('lexique.twig', $context);

your lexique.twig file would be:

<article>
  <h1 class="headline">{{post.post_title}}</h1>
  <div class="body">
    {{post.content}}
  </div>
</article>