S
S
sasha7612019-08-11 10:33:14
WordPress
sasha761, 2019-08-11 10:33:14

How to display pagination on a separate page template?

Good afternoon, I created a separate page template where I write down all the products with discounts. I output everything there in a cycle, but I can’t screw the pagination in any way. Tell me please .
Here is the code for how I display products with discounts

global $woocommerce_loop;
    $atts = shortcode_atts( array(
      'per_page' => '12',
      'columns'  => '4',
      'orderby'  => 'title',
      'order'    => 'asc'
    ), $atts );
    
    $meta_query = WC()->query->get_meta_query();      
    $product_ids_on_sale = wc_get_product_ids_on_sale();
    $query_args = array (
      'posts_per_page' => 8,
      'no_found_rows' => 2,
      'post_status' => 'publish',
      'post_type' => 'product',
      'meta_query' => $meta_query,
      'post__in' => array_merge( array( 0 ), $product_ids_on_sale )
    );
    $products = new WP_Query ($query_args);


      // ob_start();
      // $products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
      $columns = absint( $atts['columns'] );
      $woocommerce_loop['columns'] = $columns;

      if ( $products->have_posts() ) : ?>

        <?php woocommerce_product_loop_start(); ?>

        <?php while ( $products->have_posts() ) : $products->the_post(); ?>

          <?php wc_get_template_part( 'content', 'product' ); ?>


        <?php endwhile; // end of the loop. ?>

        <?php woocommerce_product_loop_end(); 
      wp_pagenavi(array( 'query' => $products ));
      woocommerce_pagination(array( 'query' => $products ));
     wc_get_template( 'loop/pagination.php' ); 
      ?>

      <?php endif;
      wp_reset_postdata();
    ?>
    </div>
    <?php 
    woocommerce_pagination(array( 'query' => $products ));
    the_posts_pagination( array(
      'show_all'     => false, // показаны все страницы участвующие в пагинации
      'end_size'     => 1,     // количество страниц на концах
      'mid_size'     => 3,     // количество страниц вокруг текущей
      'prev_next'    => false,  // выводить ли боковые ссылки "предыдущая/следующая страница".
      'prev_text'    => __('« Previous'),
      'next_text'    => __('Next »'),
      'add_args'     => false, // Массив аргументов (переменных запроса), которые нужно добавить к ссылкам.
      'add_fragment' => '',     // Текст который добавиться ко всем ссылкам.
      'screen_reader_text' => __( 'Posts navigation' ),
    ) );

As you can see, I try to display a bunch of pagination but it doesn’t work

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question