Last active
August 29, 2015 14:26
-
-
Save spacetrack/49ad773aee84bca53ec3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// always exclude the first story from index pages! | |
if (!function_exists('archive_exclude_first_post')) { | |
function archive_exclude_first_post($query) | |
{ | |
if (is_admin() || !is_archive() || !$query->is_main_query()) { | |
return; | |
} | |
$offset = 1; | |
$posts_per_page = get_option('posts_per_page'); | |
if ($query->is_paged) { | |
$offset = $offset + | |
(($query->query_vars['paged'] - 1) * $posts_per_page); | |
} | |
$query->set('offset', $offset); | |
} | |
} | |
add_action('pre_get_posts', 'archive_exclude_first_post'); | |
if (!function_exists('archive_adjust_offset_pagination')) { | |
function archive_adjust_offset_pagination($found_posts, $query) | |
{ | |
if (is_admin() || !is_archive() || !$query->is_main_query()) { | |
return $found_posts; | |
} | |
$offset = 1; | |
return $found_posts - $offset; | |
} | |
} | |
add_filter('found_posts', 'archive_adjust_offset_pagination', 1, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://coke-zettelkasten.tumblr.com/post/126019556991/offset-in-wordpress-wpquery