0

I know similar questions have been asked, but none of them seem to answer the question.

I've set up a post-loop widget that I put on the home page. It has pagination, but whenever going to any page other than the first, I get a nasty 404. The reason is because, when the URL gets a /page/2/ or a /?page=2 in it, WordPress no longer directs the call to the home page template. Instead it seems to assume there's a page with that name, it can't find it, and so it throws a 404.

Thus, my question is, when / why does WordPress decide that it isn't the home page? and why? And how do I force it to keep using the home page template? (i.e. front-page.php)

Update

It seems that, after switching my home page display from "Your latest posts" (which was irrelevant since the theme/child theme junks anything and replaces it with its widgets when active) to "A static page" (I chose a random page, which doesn't display anyhow), it now, instead of giving a 404, just stays on page 1, even though /page/2 is shown in the URL (the other commonly reported error).

0

You will need to take the value of /page/n and pass it into your custom loop:

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;    
$the_query = new WP_Query( 'posts_per_page=3&paged=' . $paged ); 

You can read more here: https://codex.wordpress.org/Pagination

  • Sorry if I wasn't super clear.. :-/ I was doing that, but it still wasn't working. – Codesmith Jan 27 '17 at 21:50
0

After a bit of research and playing with it, I did get it to work.

Issue 1
The first trick (as mentioned above) was to switch the home page display to use "A static page." This eliminated the 404 issue, but didn't fix the pagination staying on page 1.

Issue 2
The second issue I fixed by getting the 'page' query var instead of the 'paged' query var, as per the WP get_query_var documentation page:

For getting the current pagination number on a static front page (Page template) you have to use the 'page' query variable

This seems to work great:

$page = is_front_page() ? 'page' : 'paged';
$query .= '&paged=' . get_query_var($page,1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.