• Resolved mistergoomba

    (@mistergoomba)


    Right now in category.php, I have an if($paged) statement.

    If $paged returns 0, then we are on the first page and I only show 5 posts. Else, show all 10 posts as intended.

    The problem is that there are 5 missing posts, because the first page only showed 5 instead of 10.

    Is there anyway to offset the other pages back so I can make sure all posts are visible?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • It might help if we could see the code that contains your if statement & queries. If its more than 10 lines long, drop a copy into the WordPress pastebin and post the pastebin url here. Perhaps someone will be able to spot the problem and suggest a solution.

    Thread Starter mistergoomba

    (@mistergoomba)

    It’s a simple statement, really:

    if($paged) {
        while ( have_posts() ) :
            the_post();
        }
    } else {
        $i = 0;
        while ( have_posts() && $i++ < 5 ) :
            the_post();
        }
    }

    I’ll probably ending up changing the query on page 1 rather than over-query and just stop displaying after the 5th post. However, whatever method I use for that, I assume doesn’t affect pages 2 and beyond.

    Thanks

    You’re approaching this from the wrong direction. You should have 2 slightly different queries – not 2 different Loops.

    if( !is_paged() ) { // we are on the first page
    	global $query_string;
    	query_posts( $query_string . '&posts_per_page=5' );
    }
    if ( ! have_posts() ) : while ( have_posts() ) : the_post();

    http://codex.wordpress.org/Function_Reference/is_paged
    http://codex.wordpress.org/Function_Reference/query_posts

    Thread Starter mistergoomba

    (@mistergoomba)

    Very cool, thanks! My first page is a little more efficient now :}

    However, this doesn’t solve my problem. Page 2 assumes that Page 1 had 10 posts, not 5. Therefore 5 posts go unseen.

    Thread Starter mistergoomba

    (@mistergoomba)

    Okay, I found the offset parameter. Thanks again for the help!

    $offset = (($paged - 2) * 10) + 5;
        global $query_string;
        query_posts( $query_string . '&offset=' . $offset );
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Offset the posts in category.php’ is closed to new replies.