gpt4 book ai didi

php - 没有重复帖子的嵌套循环wordpress

转载 作者:搜寻专家 更新时间:2023-10-31 21:57:33 25 4
gpt4 key购买 nike

我想循环显示总共 16 个不同的帖子,它将分成 4x。秒 x4 循环将每个显示 1 个帖子,1 中总共有 4 个帖子。帖子不重复!请帮助我!

<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>

最佳答案

像这样的东西应该可以工作:

<?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>

关于php - 没有重复帖子的嵌套循环wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31955168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com