I would like to create a page template that does a listing of all pages across all blogs within a multisite network and list those pages starting with the blog name of the site and then list out the pages within that site. So far so good.
This post got me 99% of the way there: How to list all network sites on one page
The last part I need help with is sorting the output by blogname. I tried sorting by path, but that didn’t seem to work.
Here’s what I have so far:
$blogs = $wpdb->get_results(
"SELECT blog_id,path FROM {$wpdb->blogs}
WHERE blog_id != {$wpdb->blogid}
AND site_id = '{$wpdb->siteid}'
AND spam = '0'
AND deleted = '0'
AND archived = '0'
order by blog_id", ARRAY_A
);
*/
// get all blogs
$blogs = get_blog_list( 0, 'all' );
if ( 0 < count( $blogs ) ) :
foreach( $blogs as $blog ) :
switch_to_blog( $blog[ 'blog_id' ] );
if ( get_theme_mod( 'show_in_home', 'on' ) !== 'on' ) {
continue;
}
$description = get_bloginfo( 'description' );
$blog_details = get_blog_details( $blog[ 'blog_id' ] );
?>
<li class="no-mp">
<h2 class="no-mp blog_title">
<a href="<?php echo $blog_details->path ?>">
<?php echo $blog_details->blogname; ?>
</a>
</h2>
<div class="blog_description">
<!-- <?php echo $description; ?> -->
</div>
<?php
$args = array(
'depth' => 4,
'child_of' => '',
'title_li' => '',
'echo' => 1,
'sort_column' => 'menu_order, post_title',
'post_type' => 'page',
'post_status' => 'publish'
);
?>
<?php wp_list_pages( $args ); ?>
</li>
<?php endforeach;
endif; ?>
</ul>
This can work using the following
get_blog_list
, originally by Frank Bueltge, and modified to also return each blog name and description. Attention to the use ofget_current_blog_id()
andswitch_to_blog()
.Call the function and use a sorting function. A simple example: