Answer the question
In order to leave comments, you need to log in
How to separate blocks in a wordpress loop?
Help to separate the output of records in a cycle ; I display
the news record type;
now the cycle looks like this
<div class="news">
<div class="item">
<a href="news1">Новость1</a>
</div>
<div class="item">
<a href="news2">Новость2</a>
</div>
<div class="item">
<a href="news3">Новость3</a>
</div>
<div class="item">
<a href="news4">Новость4</a>
</div>
</div>
<div class="news">
<div class="item">
<a href="news1">Новость1</a>
<a href="news2">Новость2</a>
</div>
<div class="item">
<a href="news3">Новость3</a>
<a href="news3">Новость4</a>
</div>
</div>
<div class="news">
<?php
// Запрашиваем продукты
$query = new WP_Query( [
'post_type' => 'news',
'posts_per_page' => 6,
'paged' => get_query_var( 'page' ),
] );
// Обрабатываем полученные в запросе продукты, если они есть
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();?>
<div class="item">
<a href="<?php the_permalink() ?>"><?php the_title(); ?>
</div>
<?php }
wp_reset_postdata();
}
?>
</div>
Answer the question
In order to leave comments, you need to log in
Through the remainder of the division
Rough example
foreach (range(1, 4) as $i => $item) {
if ($i > 0 && $i % 2 == 0) {
echo '</div><div class="item">';
}
echo '<a href="news' . $item . '">Новость' . $item . '</a>';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question