Pagination isn't working
-
I’m running a multisite install. One of my sites has 9 uncategorized posts (just getting started). I have a custom page template (page-news.php) where I would like to display the latest 3 posts with pagination. The code below shows the top 3 posts, with “Older Entries” at the bottom. When you click the older entries link, it takes you to “…/page/2/”, and outputs, quite literally, the same three posts found on the previous page. Thoughts? I’m sure it’s something simple, but I think I’ve been staring at it for too long and I’m starting to lose my mind…
<?php // set up or arguments for our custom query $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query_args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'paged' => $paged ); // create a new instance of WP_Query $the_query = new WP_Query( $query_args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // the loop ?> <h3 style="margin: 0px 0px 0px 0px;"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3> <div class="news-page-news-date"><?php the_time('F j, Y') ?></div> <div style="float:right; padding:0px 0px 10px 10px;"> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail'); ?> <?php endif; ?> </div> <?php the_excerpt(); ?> <hr> <?php endwhile; ?> <?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="prev-posts-link"> <?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); ?> </div> <div class="next-posts-link"> <?php echo get_previous_posts_link( 'Newer Entries' ); ?> </div> </nav> <?php } ?> <?php else: ?> <h3>Sorry...</h3> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Pagination isn't working’ is closed to new replies.