Answer the question
In order to leave comments, you need to log in
How to wrap the first 4 posts of a wordpress cycle in a div?
Hello! You need to enclose the first 4 posts of the category in a div, and the rest do not. Moreover, if the post is less than 4, so that the div is closed. I know that you need to use a counter for this, but I don’t know how to solve it.
Found the code, but it wraps in a div every 4 posts. And I only need to do it once.
Answer the question
In order to leave comments, you need to log in
In the end, I solved the problem myself.
<?php $i = 0;
while (have_posts()) : the_post(); ?>
<?php if ($i === 0) {
echo '<div class="box">';
} ?>
// Здесь другая логика
<?php
if ($i === 3) {
echo '</div>';
}
$i++;
endwhile; ?>
<?php if ($i <= 3) {
echo '</div>';
} ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question