Skip to content

Instantly share code, notes, and snippets.

@OscarAbadFolgueira
Last active February 23, 2016 14:27
Show Gist options
  • Save OscarAbadFolgueira/ab6d3bc0ae1910c7ee32 to your computer and use it in GitHub Desktop.
Save OscarAbadFolgueira/ab6d3bc0ae1910c7ee32 to your computer and use it in GitHub Desktop.
This WordPress code snippet set the number of posts per pages depending the page
/**
* This WordPress code snippet set the number of posts per pages depending the page
*
* Author: Oscar Abad Folgueira
* Author URI: http://www.oscarabadfolgueira.com
*
* You can copy this snippet and paste in your functions.php or you can build your own plugin
*
* Change the number of posts per page on each case.
*/
function number_of_posts_per_page( $number ) {
if ( is_home() ) {
$number->set( 'posts_per_page', 15 );
} elseif ( is_category() ) {
$number->set( 'posts_per_page', 10 );
} elseif ( is_tag() ) {
$number->set( 'posts_per_page', 12 );
} elseif ( is_author() ) {
$number->set( 'posts_per_page', 10 );
} elseif ( is_search() ) {
$number->set( 'posts_per_page', 15 );
} elseif ( is_archive() ) {
$number->set( 'posts_per_page', 15 );
}
} // End of number_of_posts_per_page() function
// Action for set the number of posts per page
add_action('pre_get_posts', 'number_of_posts_per_page');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment