Answer the question
In order to leave comments, you need to log in
How to wrap every 4 posts in a div?
How to wrap every 4 posts with wp_query function in a div?
Give a more detailed answer.
Thank you)
<?php $args = array(
'posts_per_page' => 5,
'orderby' => 'date',
'category_name' => 'team',
);
$query = new WP_Query( $args );
// Цикл
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
?>
<div class="specialist col-6">
<div class="sp-block-left">
<div class="image-sp" style="background-image: url('<?php echo $thumb_url[0]; ?>');"></div>
</div>
<div class="sp-block-right">
<a href="<?php the_permalink(); ?>"><h3><?php the_title();?></h3></a>
<p class="despription"><?php the_tags(); ?></p>
<p><?php the_excerpt(); ?></p>
</div>
</div>
<?php
}
}
wp_reset_postdata();?>
Answer the question
In order to leave comments, you need to log in
via array_chunk($array,4);
$args = array(
'posts_per_page' => 5,
'orderby' => 'date',
'category_name' => 'team',
);
$postsArr = get_posts( $args );
$chunkPosts = array_chunk($postsArr ,4);
foreach($chunkPosts as $posts){
echo '<div class="див блока">';
foreach($posts as $post){
// Выводим посты в блоке.
}
echo '</div>';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question