This is a solution written basing on Tom J Nowell idea and answer. It prints out sorted list of all sites in Wordpress Multisite installation, as simple line (separated with pipe).
To get this solution running, edit your currently selected theme and select shortcodes.php from right sidebar. Near the end of this file, before first occurence of add_shortcode call add following function:
function theme_list_all_network_sites()
{
global $wpdb;
$result = '';
$sites = array();
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
if(!empty($blogs))
{
foreach($blogs as $blog)
{
$details = get_blog_details($blog->blog_id);
if($details != false)
{
$url = $details->siteurl;
$name = $details->blogname;
if(!(($blog->blog_id == 1) && ($show_main != 1)))
{
$sites[$name] = $url;
}
}
}
ksort($sites);
$count = count($sites);
$current = 1;
foreach($sites as $name=>$url)
{
$result.= '<a href="'.$url.'">'.$name.'</a>';
$result.= ($current == $count) ? "\n" : ' | ';
++$current;
}
}
return $result;
}
Then scroll down to the end of file and after last occurence of add_shortcode add:
add_shortcode('network_list', 'theme_list_all_network_sites');
Click Update File to save your changes.
Now, whenever anyone use [network_list] shortcode to in post, page or theme element, a list of network sites will be printed in place of that shortcode.