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).
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).
Share Improve this question edited Jan 27, 2017 at 20:58 Codesmith asked Jan 27, 2017 at 20:30 CodesmithCodesmith 1671 silver badge8 bronze badges2 Answers
Reset to default 1You 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/Pagination
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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745156290a4614140.html
评论列表(0条)