[wp-trac] [WordPress Trac] #18897: query_posts / WP_query parameter 'offset' should play nicely with 'paged'
WordPress Trac
noreply at wordpress.org
Fri Nov 29 21:57:43 UTC 2013
#18897: query_posts / WP_query parameter 'offset' should play nicely with 'paged'
------------------------------------------+-----------------------------
Reporter: here | Owner: wonderboymusic
Type: enhancement | Status: reopened
Priority: normal | Milestone: 3.8
Component: Query | Version: 3.2.1
Severity: normal | Resolution:
Keywords: has-patch commit needs-codex |
------------------------------------------+-----------------------------
Comment (by SergeyBiryukov):
Replying to [comment:14 bradyvercher]:
> Using the other example I mentioned above, say I want 5 posts on the
first page of an archive and 10 on subsequent pages -- that's no longer
possible without allowing `offset` to be negative (attached patch allows
for that).
That would indeed require a negative offset, but it wasn't possible before
this change either, unless I'm missing something. This code works the same
way for me in both 3.7.1 and current trunk (posts 6 to 10 are never
displayed):
{{{
function change_posts_per_page_18897( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( $query->is_paged() ) {
$query->set( 'posts_per_page', 10 );
} else {
$query->set( 'posts_per_page', 5 );
}
}
add_action( 'pre_get_posts', 'change_posts_per_page_18897' );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18897#comment:16>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list