Php 在自定义wordpress循环中每4篇文章用div换行一次
嗨,Php 在自定义wordpress循环中每4篇文章用div换行一次,php,wordpress,loops,row,Php,Wordpress,Loops,Row,嗨, 我以前从未这样做过。我正在尝试将上面循环中的每4篇文章包装在一个中,这应该能帮你解决问题 <?php $args = array( 'post_type' => 'college', 'posts_per_page' => -1, 'order' => 'DESC', 'orderby' => 'menu_order' ); $the_query = new WP_Q
我以前从未这样做过。我正在尝试将上面循环中的每4篇文章包装在一个
中,这应该能帮你解决问题
<?php
$args = array(
'post_type' => 'college',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'menu_order'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-3">
<?php the_title(); ?>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
$args=array(
“post_type”=>“college”,
“每页帖子数”=>-1,
“订单”=>“描述”,
'orderby'=>'菜单\u顺序'
);
$thew_query=newwp_query($args);
如果($the\u query->have\u posts()):
$counter=0;
while($the_query->have_posts()):$the_query->the_post();
如果($counter%4==0):
echo$计数器>0?"" : ""; // 如果不是第一次,请关闭div
回声“;
endif;
?>
改编自Great:)这是一个很好的挑战,让我写了一些东西
$args = array(
'post_type' => 'college',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'menu_order'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
$counter = 0;
while ($the_query->have_posts()) : $the_query->the_post();
if ($counter % 4 == 0) :
echo $counter > 0 ? "</div>" : ""; // close div if it's not the first
echo "<div class='row'>";
endif;
?>
<div class="col-3">
<?php the_title(); ?>
</div>
<?php
$counter++;
endwhile;
endif;
wp_reset_postdata();
?>