WPquery +每第n个元素添加一行
问题描述:
因此,如果下面的情况 - 我有一个wpquery喜欢下面的代码。WPquery +每第n个元素添加一行
<section class="row service_block_row bgf" id="page-<?php the_ID(); ?>">
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query($args);
if ($parent->have_posts()) : ?>
<?php while ($parent->have_posts()) : $parent->the_post(); ?>
<div class="row">
<div class="col-sm-12 col-lg-3">
<h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
</div>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</div>
</div>
</div>
</section>
我想达成什么是有循环那样工作:
<ROW>
<COL-LG-3>
<COL-LG-3>
<COL-LG-3>
<COL-LG-3>
</ROW>
所以其实我会艾克实现是有里面的第4个元素,而无需创建不同的环路。我知道我应该使用一些柜台,但我不知道怎么样;/
感谢
答
添加新行后4周的cols
<section class="row service_block_row bgf" id="page-<?php the_ID(); ?>">
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query($args);
if ($parent->have_posts()) :
$count=0;
?>
<div class="row">
<?php while ($parent->have_posts()) : $parent->the_post();
$count++;
?>
<div class="col-sm-12 col-lg-3">
<h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php
if($count%4==0)
{
echo '</div><div class="row">';
}
endwhile; ?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</div>