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

Asked

Viewed 180 times

0

I am creating a theme in Wordpress and the time has come to make the pagination.

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

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

In the index of my template, I set 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 is the code where I create the pagination that is 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 finally, I call the template function this way:

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

I think it’s a problem with . htaccess, but I can’t identify the problem. I’ve tried changing the format to /page/%#% or /paged/%#% but it didn’t work out.

  • 1

    Instead of editing the question, create a new answer with the code you used to solve the problem, so it is cataloged here for those who search later.

  • 1

    and don’t use query_posts is sure of headache.

  • OK @Ricardomoraleida. I will change the question again by inserting the answer. Thanks for the tip, the answer and not using query_posts

1 answer

1

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

Solving my problem

I managed to resolve 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, thank you Ricardo for the tips

Browser other questions tagged

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