Wordpress: paginate_links() does not work on the page Category.php

Asked

Viewed 13 times

0

I am creating a new page to list only posts from a specific category using the "Category.php" template, but when using the pagination that is being generated through Function paginate_links(), instead of going to the desired page, it goes back to my home page, as if wordpress had failed to map the route(url) of the page. Could you help me? Follow my code below:

<div class="col-sm-9">
      <?php
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        $args = array(
          'posts_per_page' => 1,
          'paged' => $paged,
          'cat' => 4
        );
        $the_query = new WP_Query( $args ); 
        // The Loop
        if ( $the_query->have_posts() ) { ?>
          <div class="row">
            <?php while ( $the_query->have_posts() ) : ?>
              <?php $the_query->the_post(); ?>
              <?php get_template_part('components/post'); ?>
              <?php
              endwhile;
              ?>
          </div>
          <div class="row pagination my-2 justify-content-center">

            <?php
             echo paginate_links(array(
              'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
              'total' => $the_query->max_num_pages,
              'current' => max(1, get_query_var('paged')),
              // 'format' => '?paged=%#%',
              'show_all' => true,
              'type' => 'plain',
              'end_size' => 2,
              'mid_size' => 1,
              'prev_next' => true,
              'prev_text' => sprintf('<i></i> %1$s', __('Anterior', 'Anterior')),
              'next_text' => sprintf('%1$s <i></i>', __('Próximo', 'Próximo')),
              'add_args' => false,
              'add_fragment' => '',
            )); ?>
          </div>
          <?php 
            }
          else {
            echo "Não existem posts";
          }
          ?>
      </div>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.