• Resolved Patrick_O

    (@patrick_o)


    I am building a theme with two columns.
    Every “page” has 10 posts on it. But I want the first page to have 9 posts on it, so I can use one of the post spaces for other things.

    If I do this the following way, the first page will show post 1 t/m 9 and the second page will show post number 11 t/m 20.

    <?php $i=1; while ( (have_posts()) && ($i<11) ): the_post(); ?>
    	<div class="box<?php if($i%2==0) echo '-second'; ?>">
    	<?php /*	The content here	*/ ?>

    I totally understand why this happenes, but I can’t seem te figure out how to do it the right way.
    My best “guess” is that I need to use this:

    query_posts('posts_per_page=5');

    But how, I don’t know.

    Can someone help me out here?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Sorry, but what’s the question?

    Thread Starter Patrick_O

    (@patrick_o)

    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.

    Thread Starter Patrick_O

    (@patrick_o)

    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.

    Thread Starter Patrick_O

    (@patrick_o)

    Thank you all for your help!
    This article (weblogtoolscollection.com) does the trick for me…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘First page 9 post, the others 10?’ is closed to new replies.