我的模板中有额外的字段,它看起来像: “>
<div class="entry-content clearfix">
<div class="col-left">
<?php the_content(); ?>
</div>
<div class="col-right">
<?php
if(function_exists('get_field')) {
$sc = get_field('second_column');
echo apply_filters( the_post_thumbnail( 'thumbnail' ), $sc );
}
?>
</div>
</div><!-- .entry-content -->
</div><!-- #post-## -->
它应该是这样的:col-left显示帖子(最近10个)和col-right显示thumnail到每个帖子。
我应该如何放置此模板中的所有内容?坐了一会儿,不知道。最好的,但不能正常工作的是:
<?php if ( $category_posts->have_posts() ) ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content clearfix">
<div class="col-left">
<?php while ( $category_posts->have_posts() ) : $category_posts->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<div class="col-right">
<?php
while ( $category_posts->have_posts() ) : $category_posts->the_post();
if(function_exists('get_field')) {
$sc = get_field('second_column');
echo apply_filters( the_post_thumbnail( 'thumbnail' ), $sc );
}
?>
</div>
</div><!-- .entry-content -->
</div><!-- #post-## -->
答案 0 :(得分:2)
Tomu,如果你想在同一页面上运行两次循环,那么你必须使用<?php rewind_posts(); ?>
。您可以尝试以下代码。
<?php if ( $category_posts->have_posts() ) ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content clearfix">
<div class="col-left">
<?php while ( $category_posts->have_posts() ) : $category_posts->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<div class="col-right">
<?php rewind_posts(); ?>
<?php
while ( $category_posts->have_posts() ) : $category_posts->the_post();
if(function_exists('get_field')) {
$sc = get_field('second_column');
echo apply_filters( the_post_thumbnail( 'thumbnail' ), $sc );
}
?>
</div>
</div><!-- .entry-content -->