Forrest Forrest - 8 months ago 55
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

and here is my code

// 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 ?>
<h1><?php echo the_title(); ?></h1>
<div class="excerpt">
<?php the_excerpt(); ?>
<?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 class="next-posts-link">
<?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
<?php } ?>

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

The website (temporary) can be seen here

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.


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

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