wp_query, offset and pagination give an extra (last) empty page
-
I need to exclude the latest post from the loop.
I have done this with ‘offset’, but then the pagination didn’t work.
After researching and googling I have found some snippets of code that did the trick for pagination! Only problem is that I get an extra empty page with no posts on it.I have currently only 5 posts (6 with the latest one that I want excluded).
If I set number of posts per page in settings to 3, everything is ok.
If I set it to 5, I should get only one page, but the link to second page still appears and on that second page, there is nothing…Any idea how to work around that?
This code is in my functions.php:
function my_post_limit($limit) { global $paged, $myOffset; if (empty($paged)) { $paged = 1; } $postperpage = intval(get_option('posts_per_page')); $pgstrt = ((intval($paged) -1) * $postperpage) + $myOffset . ', '; $limit = 'LIMIT '.$pgstrt.$postperpage; return $limit; }
This code is in my index.php:
[Code moderated as per the Forum Rules. Please use the pastebin]
- The topic ‘wp_query, offset and pagination give an extra (last) empty page’ is closed to new replies.