WP_Dummy
Member
Posted 1 year ago #
Hi,
I have a couple of custom archive pages where I limited the number of post by using this code:
<?php
$posts = query_posts($query_string .
'&showposts=10');
if (have_posts()) : while (have_posts()) : the_post(); ?>
For page 1 to page 7 the pagination is fine.
however when it comes to page 8 till the last page, they all goes to 404 error page.
I checked other archive pages where there are not using the code above, they all functioning well. So I conclude that is the code above that causing this problem.
Any idea to fix this problem?
I am guessing that the showposts change is made after the pagination has been calculated. Try this:
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(
array_merge(
$wp_query->query,
array('posts_per_page' => 10,
'paged' => $paged,
)
)
);
WP_Dummy
Member
Posted 1 year ago #
nope, it doesn't work as well.
Maybe it has to do with the function "query_post" itself?
I don't think it is query_posts.
Did you use the code exactly as I posted it? How did it fail? How many posts do you have?
A link to your site might help.
WP_Dummy
Member
Posted 1 year ago #
Yes, i did use the code u gave me. But it still not working.
Sure you can goto see my site :
The pagination works until page 17
http://www.myhphone.com/news/page/17/
and start from page 18, its not working anymore.
http://www.myhphone.com/news/page/18/
WP_Dummy
Member
Posted 1 year ago #
How many posts do you have? In other words, how many pages should there be?
WP_Dummy
Member
Posted 1 year ago #
What happens if you set Admin->Settings->Reading->'Blog pages show at most' to 10?
How many posts do you have?
WP_Dummy
Member
Posted 1 year ago #
I got set the 'Blog pages show at most' to 20, which is for my other category page that does not using the query_post code. They all works well.
I have thousands of post in my site.
I am trying to determine if the calculation of the number of pages is incorrect. You may have thousands of posts, but how many should be found in the page that is failing?
Please set 'Blog pages show at most' to 10 and see if it makes a difference in the pagination on the page that is failing.
WP_Dummy
Member
Posted 1 year ago #
It works when its set to 10 posts.
So, when the pagination is failing, the calculation of the number of pages is done using 10 (34), but the highest page number you can see is calculated using 20 (17).
Please set 'Blog pages show at most' back to 20.
I wonder if there is something else in your code that is causing the problem. Is there a 'reset' after the query_posts?
Please post the code for the page in a pastebin and post a link to it here.
WP_Dummy
Member
Posted 1 year ago #
Okay, I set it back to 20.
Nope I did not use reset in my query_post.
the code of the page is at here : http://pastebin.com/sa48h7iA
WP_Dummy
Member
Posted 1 year ago #
Okay, I set it back to 20.
Nope I did not use reset in my query_post.
the code of the page is at here : http://pastebin.com/sa48h7iA
Please put in the code I suggested and put it in the pastebin.
WP_Dummy
Member
Posted 1 year ago #
http://pastebin.com/x0TMKA0J
I don't know whether I put the code correctly. If you cannot view it, maybe I should paste it here?
By the Forum rules, you can't post long bits of code here. You must use the pastebin.
Both of the pastebins show your old code. Please put in the code I suggested, run it to make sure there are no errors, and put it in a pastebin.
thelumberjack
Member
Posted 1 year ago #
Try replacing your query with the following code:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array(
'showposts' => 10,
'paged' => $paged
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>
WP_Dummy
Member
Posted 1 year ago #
@thelumberjack: I think he needs to keep the original query args because he is restricting to a category query.
WP_Dummy
Member
Posted 1 year ago #
@thelumberjack : I had tried this trick before, but still unable to solve the problem. Anyway thanks for the advise.
thelumberjack
Member
Posted 1 year ago #
Damn. I had a very similar problem and the code I pasted worked for me. Best of luck with finding a solution!
Sorry, but after all the effort you had to show me what I asked for, I don't see the problem.
I don't have an answer for you.
WP_Dummy
Member
Posted 1 year ago #
@vtxyzzy : It's ok, but I really appreciate what you have done for me. Maybe I should set 'Blog pages show at most' back to 10. Then it settle all the hassle.
WP_Dummy
Member
Posted 1 year ago #
I already use this plugin. Still not helping.
From other posts on this forum, I think this is a bug in WordPress that happens when the 'Blog shows at most' value is higher than the value used in a query.
I have not seen a solution.