How to show a single post on the front page but have normal paging?

I solved it using the offset query parameter. This allowed me to edit the query in the pre_get_posts hook, and seems to be the cleanest way to do this, without a new query. Now the home page shows only one post, and page/2/ shows posts 2-11. All links keep working, no other modification is required.

add_action('pre_get_posts', 'set_offset_on_front_page');
function _set_offset_on_front_page(&$query)
{
    if (is_front_page() && is_paged()) {
            $posts_per_page = isset($query->query_vars['posts_per_page']) ? $query->query_vars['posts_per_page'] : get_option('posts_per_page');
            // If you want to use 'offset', set it to something that passes empty()
            // 0 will not work, but adding 0.1 does (it gets normalized via absint())
            // I use + 1, so it ignores the first post that is already on the front page
            $query->query_vars['offset'] = (($query->query_vars['paged'] - 2) * $posts_per_page) + 1;
    }
}

Leave a Comment