R
R
Roman Serkov2018-04-23 12:36:22
WordPress
Roman Serkov, 2018-04-23 12:36:22

Pagination on WP not working, how to solve the problem?

connected the standard pagination function still does not work, did it through plugins and found functions on the internet, nothing helps, help solve the problem.

<?php
/*
Template Name: index
*/
?>
<?php get_header( ); ?>
<main>
  <div class="container">
    <div class="bg">

      <?php get_template_part( 'template-parts/breadcrumbs') ?>

      <div class="material">
        <p>В категирии материалов: 1233456</p>
        <p>Показанно материалов: 1-10</p>
      </div>
      <p class="sort">
        Сортировать по:
        <a href="#">дате &#183;</a>
        <a href="#">названию &#183;</a>
        <a href="#">Рейтингу &#183;</a>
        <a href="#">загрузкам &#183;</a>
        <a href="#">просмотрам</a>
      </p>
      <h3 class="free_intro">
        <?=get_theme_mod('text_index_page')?>
      </h3>

      <section class="flex-container">

      <?php 
        // параметры по умолчанию
      $args = array(
        'numberposts' => 6,
        'category'    => '2,5',
        'orderby'     => 'date',
        'order'       => 'DESC',
        'post_type'   => 'post',
          'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
        );

      $posts = get_posts( $args );

      foreach($posts as $post){ setup_postdata($post);
        get_template_part('/template-parts/video_posts' , get_post_format() ); 
      }

wp_reset_postdata(); // сброс
?>


          </section>

</div>
</div>

</main>

<?php get_footer( ); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Medar, 2018-04-23
@Fobz

This is a standard issue that is easy to google: "wp get_posts pagination". Learn to search for information.
In short, you need to add 'paged' to the request:

$paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
$posts = get_posts( array('paged' => $paged) );

In general, this works. But there are a lot of nuances on custom posts, taxonomy, etc. Try, study, learn to debug.
And it's better to use WP_Query instead of get_posts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question