Howdy
You can’t change the query within the loop. I would suggest have a conditional before your arguments manipulating posts_per_page (or $maxposts) depending on what $pageNumber is.
Hi there,
Thanks for your reply! You mean like this:
if($paged) :
$maxposts = 4;
else:
$maxposts = 3;
endif;
I tried that allready and it works sort of however somehow post nr. 5 dissapears?
That’s because the query thought you were displaying 4 posts on the first page, you’ll need to use the offset parameter as well.
Thanks for that, I changed it to:
if($paged) :
$maxposts = 4;
if ($pageNumber == 2):
$offset = 3;
endif;
else:
$maxposts = 3;
endif;
And that’s working! But now the pagination is messed up.
I have 8 posts in total. On page 1 the wp_paginate shows that there are 3 pages (which is correct 3+4+1=8), but on page 2 it shows there are only 2 pages. When I try to access page/3/ there’s no post in it…
Any thoughts?
Try:
if($paged) :
$maxposts = 4;
$offset = 3;
else:
$maxposts = 3;
endif;
The offset should be used on every page except the first. Let me know how it works out.
Sorry, this:
if($paged > 1) :
$maxposts = 4;
$offset = 3;
else:
$maxposts = 3;
endif;
Nope, same story… Page 3 doesn’t show up on page 2.
But page/3/ shows the same posts as page 2 now.
Tried it, but same result as:
if($paged > 1)
Keep them coming ๐
Something like:
if( !is_paged() ) $maxposts = 3;
wlse $maxposts = 4;
$args = array(
'posts_per_page' => $maxposts,
'post_type' => 'news-item',
'paged' => $paged
);
should work.
Thanks both of you!
My weekend just started so not able to try it out right now…
Will try your suggestions as soon as I can!
Thanks
Hi esmi,
Your solution has the same result as my first attempt: post #5 dissapears…
I’m gonna try keesiemeijer’s suggestion now, looks promising
Thanks!
Hi keesiemeijer,
Different code, same result unfortunately… But in this case the wp_paginate(); doesn’t work anymore. It doesn’t show any pagination, when I replace it with:
<?php next_posts_link('Older Entries ยป', 0); ?>
<?php previous_posts_link('ยซ Newer Entries', 0); ?>
I get the same error as in my code; on page 2 the link to page 3 isn’t there… I don’t get it anymore.
My code: http://pastebin.com/SHqS7nFZ
Any other suggestions?
Thanks!
Found a solution/workaround!
I modified my code a bit in order to let the wp_paginate() function show the right amount of pages. The function can pass the total amount of pages and the current page as variables. However, if you pass ‘pages’ the highlighting of the current page stops working so you have to pass ‘page’ as well.
My final code: http://pastebin.com/51r7PTwb