Skip to content

Instantly share code, notes, and snippets.

@spacetrack
Last active August 29, 2015 14:26
Show Gist options
  • Save spacetrack/49ad773aee84bca53ec3 to your computer and use it in GitHub Desktop.
Save spacetrack/49ad773aee84bca53ec3 to your computer and use it in GitHub Desktop.
// 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