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:
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.
yes, small source for an template.
This will print out an unordered list of all public sites in a multisite network:
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 ofadd_shortcode
call add following function:Then scroll down to the end of file and after last occurence of
add_shortcode
add: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.Since WordPress 4.6.0, I offer you a more modern way to “list” (or more) :