Forrest Forrest - 2 months ago 20
PHP Question

Wordpress Pagination on static homepage

I am trying to get Pagination working on my static homepage which I have integrated with wordpress. The problem I am having is when I click the "Older Entries" button on the page it goes to the ?paged=2 page but displays the first 10 posts still. Just like on the first page.

I know the code somewhat works because I changed

($the_query->max_num_pages > 1)
to 2 and went to the page and it displayed the contents of the second page with a "Newer Entries" button.

I just cannot get it to do it automatically.

I used this persons tutorial on how to set it up
http://callmenick.com/post/custom-wordpress-loop-with-pagination

and here is my code



<?php
// set up or arguments for our custom query
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'post',
'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(); // run the loop ?>
<article>
<h1><?php echo the_title(); ?></h1>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
</article>
<?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 ); // display older posts link ?>
</div>
<div class="next-posts-link">
<?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
</div>
</nav>
<?php } ?>

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





The website (temporary) can be seen here http://auroraservers.org/MainSite/Index.php

So you can see what it is doing.

Thank you for any help! I've been trying to fix this for over a day now so I hope it isn't too much trouble.

Answer

This line should be "paged" instead of "page"

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