Как сделать пагинацию на странице поиска (wordpress)?

<?php get_header(); ?>

<div class="content">

<?php
$current = absint(
  max(
    1,
    get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' )
  )
);
$s=get_search_query();
$the_query          = new WP_Query(
  [
    's' =>$s,
    'showposts'=>-1,
    'posts_per_page' => 8,
    'paged'          => $current,
  ]
);
if ( $the_query->have_posts() ) {
    _e("<h2 style='font-weight:bold;color:#000'>Результаты поиска для: ".get_query_var('s')."</h2>");
  while ( $the_query->have_posts() ) {
    $the_query->the_post(); ?>
    <div class="blockpost">
<h2><?php the_title(); ?></h2>
<p><?php if(get_the_excerpt()){
  the_excerpt();
}else {
  the_content();
} ?> </p>
</div>
  <?php }
  wp_reset_postdata();

  $pagination = wp_kses_post(
    paginate_links(
      [
        'total'   => $query->max_num_pages,
        'current' => $current,
      ]
    )
  );

  echo "<div class=pages-of-posts>".$pagination."</div>";
}else{
    ?>
            <h2>Ничего не найдено</h2>
              <p>Простите, но по данному запросу ничего не найдено.</p>
    <?php } 
      ?>

            </div>
<?php get_footer(); ?>

Есть такой код на вордпресс в странице search.php. Работает все как надо, вот только никак не хочет выводить пагинацию...


Ответы (0 шт):