Sorry, but what’s the question?
My question is: “How can I display 9 posts on the first (front) page and 10 posts on all the following?”
use this before the loop
global $paged, $posts_per_page;
$option_name = "posts_per_page";
if ($paged == 0) {
$newvalue = 9;
update_option( $option_name, $newvalue);
} else {
$newvalue = 10;
update_option( $option_name, $newvalue );
}
Ps : this approach is working but not gracefully working.
Thank you uwiuw,
I’v altered it just a little bit, but it does the same thing.
<?php
if (!is_paged()) {
update_option( posts_per_page, 9 );
} else {
update_option( posts_per_page, 10 );
}
?>
This only works after I refresh a page. Otherwise the last number of posts is shown.
Any suggestions why this happens or any other suggestens to “fix” my problem?
yes, as i said, it not gracefully working. This happen because what we do is change one of global option of the blog. you can see it in
wp-admin/options.php
maybe this approach will suit you more
if (!is_paged()) {
query_posts('posts_per_page=9')
}
The problem here, as i see it, is that in order to use differing amounts across pages, and maintain the correct offset in the query, you’d need to use the offset=x
parameter in the query_posts line… Ok, ok.. that’s simple enough, but when you do that, it throws off the paging, because the paging system (which refers to the paged=x paramter) would usually determine the offset for you.
In order for the offset to operate correctly you would need to detect the page (1, 2,3 etc..), and apply an offset when it’s anything but the first page, however in doing so you’d lose the ability to use next_posts_link, or previous_posts_link as you normally would because the offset screws with the paging…
There are a few blog entries around that show how others have tackled the issue.
1. weblogtoolscollection.com/archives/2008/06/19/how-to-offsets-and-paging/
2. wpengineer.com/correct-pagination-with-get_posts/
3. arricc.net/wordpress-front-page-single-post.php
Personally i don’t think it’s worth all the fiddly code just to use the built-in paging functions with an offset, in my opinion it would be easier to use the offset, drop the paging parameter and write your own paging links..
next_posts_link, or previous_posts_link
yes i remember, i got kind of problem before. Patrick_O, maybe it not worth
write your own paging links
i have done this before use paginate_links
. But after reading
weblogtoolscollection.com/archives/2008/06/19/how-to-offsets-and-paging/, i can tell this far more better approach. Thank you very much.
Thank you all for your help!
This article (weblogtoolscollection.com) does the trick for me…