I've been trying to get the 2 latest posts on my homepage; with the pagination resorting back to 10 posts per page once 'next' is clicked to get to page/2/ etc.
//detect the set number of posts per page
$ppp = get_option('posts_per_page');
// first page 2 posts
if (!is_paged()) {
$posts = get_posts('numberposts=2');
// second page with offset
} elseif($paged == 2) {
$posts = get_posts('offset=2');
// all other pages with settings from backend
} else {
$offset = $ppp*($paged-2)+2;
$posts = get_posts('offset='.$offset);
}
This is the code i've been using, which makes sense, however, only 1 post appears on page 2 with the rest not showing :S I've also noticed that as i decrease posts_per_page, via the setting in wp-admin under reading, more posts appear. Once i get to 2 posts per page, they all show up. Bizarre :S
I can't for the life of me figure out what's going wrong! :(
I got the code from; WP engineer - Correct pagination with get_posts