0

我想在 Timber 中渲染这个循环。请问我可以帮忙吗?

$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();

所以用木头连接这个环

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

但我没有任何想法这样做。

4

1 回答 1

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

您的 lexique.twig 文件将是:

<article>
  <h1 class="headline">{{post.post_title}}</h1>
  <div class="body">
    {{post.content}}
  </div>
</article>
于 2016-12-30T07:12:20.303 回答