Home WordPress Homepage Pagination Problem with WP-PageNavi
Post
Cancel

WordPress Homepage Pagination Problem with WP-PageNavi

I ran into quite an odd problem in WordPress. The homepage pagination would work on all pages except for the homepage. A simple search for WordPress homepage pagination problem did result in multiple hits, but all having the same problem. Luckily I was able to solve it for me.

I do have a general guide at: https://schurpf.com//custom-query-pagination-custom-post-type-pagination/ This should solve almost all pagination problems except for the homepage pagination problem.

In my case, the problem was only the pagination on the homepage. The solution was rather simple. The pagination variable on the homepage changes from:

1
<pre lang="php">$paged

to

1
<pre lang="php">$page

So all you have to do is assign

1
<pre lang="php">$paged = $page;

before the query_post function and loop. The entire pagination code changes to:

1
2
3
4
5
6
7
8
<pre lang="php"><?php $paged = $page;
$args= array(
'paged' => $paged
);?>
<?php query_posts( $args );?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

...

Note that you have to set

1
<pre lang="php">$paged = $page;

at the top to ensure WP-PageNavi is working correctly. Hopefully this solves all your WordPress homepage pagination problems!

This post is licensed under CC BY 4.0 by the author.
Trending Tags