Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End multiple loop issue – previous posts page is wrong!? Re: multiple loop issue – previous posts page is wrong!?

#69357
Chris Coyier
Keymaster

Yeah you gotta check if you are on a paginated page for that first query. Otherwise that first query has no idea and will just grab the most recent post. You don’t need to do that fancy stuff to know if a post is paginated though, you can just:

Code:
if ($paged) {
// do stuff
}

The $paged variable is equal to the # of page you are on. So if you are at /page/2, $paged will be 2. You can use that number to offset the query. Like

Code:
if ($paged) {
query_posts(“posts_per_page=1&offset=$paged”)
}

That offset parameter will skip the first X posts. You’ll need to adjust as needed. As in, if you show 5 posts per page, you’ll need to offset by 6 on page two, so you’ll need to do like:

Code:
$offset = (5 * $paged) + 1;

All covered in Digging Into WordPress — wink wink.