Wordpress не работает пагинация
Не работает пагинация постов
<div class="wrapper">
<?php
$posts = get_posts( array(
'numberposts' => 10,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'suppress_filters' => true,
) );
foreach($posts as $post) {
setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>" class="article-item">
<div class="article-item__img">
<?php the_post_thumbnail(); ?>
</div>
<div class="article-item__content">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
</a>
<?php } wp_reset_postdata(); ?>
<?php the_posts_pagination(); ?>
</div>
Ответы (1 шт):
Автор решения: dev4you
→ Ссылка
Пагинация довольно часто не работает с get_posts(). Попробуйте переделать свой цикл на WP_Query:
$args = array(
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'suppress_filters' => true );
$wp_query = new WP_Query( $args );
while ( $wp_query->have_posts() ) {
$wp_query->the_post();
// ваш вывод
?>
<a href="<?php the_permalink(); ?>"
classs="article-item">
<div class="article-item__img">
<?php the_post_thumbnail(); ?>
</div>
<div class="article-item__content">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
</a>
<?php }
// пагинация
the_post_pagination();
// вернем global $wp_query
wp_reset_postdata();