WordPress.org

Ready to get started?Download WordPress

Forums

12 Posts on Homepage, 20 posts thereafter (4 posts)

  1. Stashtea
    Member
    Posted 4 years ago #

    I have searched with no luck. I am kind of a noob so please forgive me if this is obvious and i am simply searching the wrong keywords.

    My problem is simple sounding:

    home.php is paged

    I have max posts set to 20. I simply need initial homepage to show 12, and everything else 20.

    PAGE 1 = 12 posts
    PAGE 2 -> infinity = 20 posts

    The problem I am running into is page 2 skips 8 posts (I assume it thinks they're on PAGE 1) .

    Can you please let me know the code to use to show only 12 posts on the initial page, and 20 posts afterwards with out 8 post coming from page 1.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    A custom query along the lines of:

    <?php
    if( !is_paged() ) $posts_per_page = 12;
    else $posts_per_page = 20;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'posts_per_page' => $posts_per_page,
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    should work.

  3. Stashtea
    Member
    Posted 4 years ago #

    Thanks kindly for your response. While this did work, the problem if page 2 skipping the first 8 posts (i believe it thinks they're on page 1) still persists.

    lets say i have 40 posts

    Page one has post 1> 12, and page 2 has posts 20-40 . Posts 13-19 are missing.

    Thanks again for your response, its greatly appreciated. Anyone see this issue before?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    Let's try a slightly different tack:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if( !is_paged() ) {
    	$posts_per_page = 12;
    	$args= array(
    		'posts_per_page' => $posts_per_page,
    		'paged' => $paged
    	);
    }
    else {
    	$posts_per_page = 20;
    	$args= array(
    		'posts_per_page' => $posts_per_page,
    		'offset' => 12,
    		'paged' => $paged
    	);
    }
    query_posts($args);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic