Change Number of Posts Displayed on Archive Page

This function, when added to functions.php, will help you add a posts_per_page query to the archive.php and archives.php pages, enabling you to further customize the output. Sourced from here

function number_of_posts_on_archive($query){     
	if ($query->is_archive) {             
		$query->set('posts_per_page', -1);    
	}     
	return $query; 
}  
add_filter('pre_get_posts', 'number_of_posts_on_archive');

I’ve encountered issues with the above code, wherein all of the get_posts and query loops used will begin to output all of the posts associated with the argument, instead of the limits mentioned. When this occurs, it is better to issue a simple global argument above the loop, within the archive.php or archives.php template and specify the number of posts to display.  Sourced from here.

global $query_string; query_posts("{$query_string}&posts_per_page=5");

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.