简体   繁体   中英

Page 2 not found (404) Wordpress Pagination

I was testing WordPress in localhost, posting articles to see how is working, everything fine, untill I had to much articles in one page and I had to go to the second page using the pagination, well I clicked the second page, but I got a 404 Not Found Page.

I looked for about 2-3 hours, tried every function, every example but the result was the same.

The home page is a static front page, is called Landing, and all the articles are set to the Blog page.

My php code from index.php:

<div class="container-medium">
    <div class="row">


        <?php while(have_posts()) : the_post(); ?>
        <div class="col-xs-12 col-sm-12 col-md-12">
            <?php the_post_thumbnail('post-thumbnail', array( 'class'   => "img-responsive desaturate attachment-post-thumbnail")); ?> 
            <h3 class="blog-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <div class="row">
                <div class="col-sm-12"><p class="blog-post-text"><?php echo get_excerpt(); ?></p></div>
                <div class="col-sm-12"><a class="btn btn-sm btn-readmore" href="<?php echo get_permalink(); ?>">Read more <i class="icon-right-open"></i></a></div>
            </div>
        <hr class="dotted">
    </div>


    <?php endwhile; wp_reset_query(); ?>
    </div> <!-- end .row -->
            <?php if ( have_posts() ) : ?>

    <!-- Add the pagination functions here. -->

    <!-- Start of the main loop. -->
    <?php while ( have_posts() ) : the_post();  ?>

    <!-- the rest of your theme's main loop -->

    <?php endwhile; ?>
    <!-- End of the main loop -->

    <!-- Add the pagination functions here. -->

    <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

    <?php else : ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

</div> <!-- end .container-medium -->

I read a bunch of similar questions but I don't get the result that I want.

Thank you!

PS: PHP Beginner

Write this above while loop

<?php


    $post_query = query_posts(array(
    'post_type'      => 'cover', // You can add a custom post type if you like
    'paged'          => get_query_var('paged', 1),
    'posts_per_page' => 1
));

?>

At bottom

  <?php

  global $wp_query;

  $big = 999999999; // need an unlikely integer

  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
   ) );

  ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM