Wordpress - From the second page is giving 404 error - Not Found

0

I'm creating a theme in Wordpress and it's time to paginate.

I was able to create the menus below indicating how many pages have and the next and previous pages.

Just by clicking next or the page number I want to see is returning the 404 Not Found error

In the index of my template, I define 1 post per page to test this way:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$post_query = query_posts(array(
    'post_type'      => 'post', 
    'paged'          => $paged,
    'posts_per_page' => 1
));
// while dos posts

And this one, is the code where I create the pagination found in functions.php

function paginacao() {
  global $wp_query;
  $big = 999999999;

  echo paginate_links(
    array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages
   )
  );
}

And, to finish, I call the function in the template this way:

<div class="paginacao">
  <?php paginacao(); ?>
</div>

I think this is a problem with .htaccess, but I can not identify the problem. I already tried to change the format to /page/%#% or /paged/%#% but did not work.

    
asked by anonymous 02.08.2017 / 17:05

1 answer

1

According to Ricardo Moraleida's tip, I answered my own question to leave cataloged and help other members if they need to.

Resolution of my issue

I was able to solve by removing the excerpt:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$post_query = query_posts(array(
    'post_type'      => 'post', 
    'paged'          => $paged,
    'posts_per_page' => 1
));

And adding this code to the end of functions.php

function posts_on_homepage( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'posts_per_page', '5' );
    }
}
add_action( 'pre_get_posts', 'posts_on_homepage' );

And again, thanks Ricardo for the tips

    
03.08.2017 / 15:51