-
-
Save billerickson/1d17daeaf8af64084a4c6af56cb5882d to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/** | |
* Custom posts per page | |
* | |
*/ | |
function be_posts_per_page( $query ) { | |
// Only run on archive pages | |
if( ! $query->is_main_query() || is_admin() || ! ( $query->is_home() || $query->is_archive ) ) | |
return; | |
$posts_first_page = 3; | |
$posts_per_page = 9; | |
$page = $query->query_vars['paged']; | |
// First Page | |
if( ! $page ) { | |
$query->set( 'posts_per_page', $posts_first_page ); | |
// Other Pages | |
} else { | |
$query->set( 'posts_per_page', $posts_per_page ); | |
$query->set( 'offset', $posts_first_page + $posts_per_page * ( $page - 2 ) ); | |
} | |
} | |
add_action( 'pre_get_posts', 'be_posts_per_page' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment