Good evening!

Tell me how to break the cycle into groups of 4 posts?

It is necessary that every 4 posts get a wrapper div.swiper-slide

$bcat = get_category_by_slug('blog'); $bid = $bcat->ID; $n = 12; $c = 1; $recent = new WP_Query("cat=".$id."&posts_per_page=".$n); while ($recent->have_posts()) : $recent->the_post(); get_template_part('blog-block'); wp_reset_postdata(); $c++; endwhile; 

    1 answer 1

      $bcat = get_category_by_slug('blog'); $bid = $bcat->ID; $n = 12; $c = 1; $recent = new WP_Query("cat=".$id."&posts_per_page=".$n); while ($recent->have_posts()) : $recent->the_post(); if($c%4 === 0){ echo '<div class="swiper-slide>'; } get_template_part('blog-block'); if($c%4 === 0){ echo '</div>'; } wp_reset_postdata(); $c++ endwhile; 
    • Thank you very much! - Anton Golubkov
    • @ AntonGolubkov if the answer has solved your problem, vote for it and tick the box. Thank you in the comments, of course, pleasant, but to highlight the correct answer is easier by rating. - αλεχολυτ