How to Paginate in All Multisite Posts

This tutorial consists of two simple steps. In the first step we create a pagination function and in the second step — the loop of posts.

Let’s begin.

Step 1. Pagination function

Actually you can try to install any pagination plugin for WordPress and use its own functions. But why we should do this if WordPress since 2.1.0 has its own pagination function — paginate_links()?

And misha_pagination() is just my wrapper for it. You can insert the following code directly to your current theme functions.php. You can also make some customization of $args array if you want.

function misha_pagination( $query ) {  
	$args = array(
		'total' => $query->max_num_pages, // total amount of pages
		'current' => ( ( $query->query_vars['paged'] ) ? $query->query_vars['paged'] : 1 ), // current page number
		'show_all' => false, // set to true if you want to show all pages at once
		'mid_size' => 2, // how much page numbers to show on the each side of the current page
		'end_size' => 2, // how much page numbers to show at the beginning and at the end of the list
		'prev_next' => true, // if you set this to false, the previous and the next post links will be removed
		'prev_text' => '«', // «
		'next_text' => '»' // »
	if( $args['total'] <= 1 ) // do not return anything if there are not enough posts
	return '<div class="navigation">
		<span class="pages">Page ' . $args['current'] . ' of ' . $args['total'] . '</span>'
		. paginate_links( $args ) .  
Pagination parameters explanation

Step 2. Get Multisite Network Posts with Pagination

The second and the last step of this small tutorial.

Here is one thing you have to know — if you want to display posts (network posts or local posts, doesn’t matter) in a custom loop with pagination — I highly recommend you to use pages with custom page templates because of the URL issues.

The main advantage here is that any page with a custom page template can be set to be displayed on your website front page in Settings > Reading.

Multisite Posts on the Front Page

With the code below you can easily display the posts from all network blogs (Network_Query allows you to include only specific blogs to the query as well) on any WordPress page, with a custom page template or without it. And any page can be displayed on a front page.

Displaying network posts in category templates or in single.php isn’t a good idea but if you really need to implement it, leave a comment after this post and I will try to help you.

Network_Query() class is a really great thing — it works just like WP_Query() but works for all the blogs in your multisite network. WordPress code doesn’t have this class by default, it is the part of my plugin — you can get it here.

Actually without my plugin installed this example won’t work for you.

Insert this code anywhere you want to show the network posts with a pagination.

// get the current page number from $wp_query['query_vars'], I mean the URL parameter, i.e. /page/2
// (!) if you use the code on the front page, change PAGED to PAGE, e.g. get_query_var('page')
$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;

// this class is similar to WP_Query but works for multisite posts, my plugin is required, the link is above in this post
$multiquery = new Network_Query( array('posts_per_page' => 1, 'paged' => $current_page) ); 
// run the loop
if( $multiquery->have_posts() ) :
	while( $multiquery->have_posts() ) : $multiquery->the_post();
  		// we need switch_to_blog() to work with get_the_post_thumbnail(), get_permalink() and some other loop functions
		switch_to_blog( $multiquery->post->BLOG_ID );
		echo '<p>' . get_the_post_thumbnail( $multiquery->post->ID ) . '<a href="' . get_permalink( $multiquery->post->ID ) . '">' . $multiquery->post->post_title . '</a></p>';
		// switch back

	// print pagination, pass the query object as a required parameter
	echo misha_pagination( $multiquery );

Please, let me know in comments if you have any questions.

Misha Rudrastyh

Misha Rudrastyh

I develop websites since 2008, so it is total of 13 years of experience, oh my gosh. Most of all I love love love to create websites with WordPress and Gutenberg, some ideas and thoughts I share throughout my blog.

Need some developer help? Contact me