我想循环显示总共16个不同帖子,它将分为4x。秒x4循环将显示每个帖子1个,总共4个帖子1个。帖子不重复! Plz帮帮我!
<div class="slide-start fl col-lg-12 clear">
<!-- start 1st loop here, big loop to get totals 16 posts -->
<div class="groupitem">
<!-- start 2nd loop here to get 4 posts -->
<div class="g-item fl">
<a class="fl clear col-lg-12 pro-img" href=""><?php the_post_thumbnail('medium');?></a>
<a class="fl clear col-lg-12 pro-tit" href=""><?php the_title() ;?></a>
<span class="fl clear col-lg-12 pro-type">Hair</span>
<p class="fl clear col-lg-12 pro-price"><span>105</span> USD <span>(0.5</span> KG)</p>
</div>
</div>
</div>
答案 0 :(得分:0)
这样的事情应该有效:
<?php
$args = array('posts_per_page' => 16);
$posts = get_posts($args);
$rows = array_chunk($posts, 4);
?>
<div class="slide-start fl col-lg-12 clear">
<?php foreach($rows as $row): ?>
<div class="groupitem">
<?php foreach($row as $post): setup_postdata($post); ?>
<div class="g-item fl">
<a class="fl clear col-lg-12 pro-img" href=""><?php the_post_thumbnail('medium');?></a>
<a class="fl clear col-lg-12 pro-tit" href=""><?php the_title() ;?></a>
<span class="fl clear col-lg-12 pro-type">Hair</span>
<p class="fl clear col-lg-12 pro-price"><span>105</span> USD <span>(0.5</span> KG)</p>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; wp_reset_postdata(); ?>
</div>