Skip to content

Instantly share code, notes, and snippets.

@rachelmccollin
Last active December 15, 2018 21:08
Show Gist options
  • Save rachelmccollin/d5ebccb8fb08b4de4008fcc015e6c51c to your computer and use it in GitHub Desktop.
Save rachelmccollin/d5ebccb8fb08b4de4008fcc015e6c51c to your computer and use it in GitHub Desktop.
WPMU DEV Listing Sites in a Multisite Network
/*
Theme Name: Child Theme for Multisite Network
Theme URI: https://github.com/rachelmccollin/wpmu-dev-list-network-sites
Description: Theme to support WPMU DEV post on adding alist of all sites to each site in the network. Child theme for the WPMUDEV Parent Theme theme.
Author: Rachel McCollin
Author URI: http://rachelmccollin.co.uk/
Template: wpmudev-parent-theme
Version: 1.0
*/
@import url("../wpmudev-parent-theme/style.css");
$subsite_id = get_object_vars( $subsite )["blog_id"];
$subsite_name = get_blog_details( $subsite_id )->blogname;
$subsite_link = get_blog_details( $subsite_id )->siteurl;
echo '<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '">' . $subsite_name . '</a></li>';
.subsites-container {
background: #3394bf;
}
ul.subsites {
list-style-type: none;
overflow: auto;
max-width: 1000px;
margin: 0 auto;
}
/* list of network sites */
ul.subsites {
list-style-type: none;
background: #3394bf;
overflow: auto;
}
ul.subsites a {
float: left;
margin: 0.5em;
color: #fff;
}
ul.subsites a:hover,
ul.subsites a:active {
text-decoration: none;
color: #183c5b;
}
ul.subsites {
list-style-type: none;
overflow: auto;
max-width: 1000px;
margin: 0 auto;
}
function wpmu_list_sites() {
$subsites = get_sites();
if ( ! empty ( $subsites ) ) {
echo '<ul class="subsites">';
foreach( $subsites as $subsite ) {
}
echo '</ul>';
}
}
add_action( 'wpmu_before_header', 'wpmu_list_sites' );
function wpmu_list_sites() {
$subsites = get_sites();
if ( ! empty ( $subsites ) ) {
echo '<ul class="subsites">';
foreach( $subsites as $subsite ) {
$subsite_id = get_object_vars( $subsite )["blog_id"];
$subsite_name = get_blog_details( $subsite_id )->blogname;
$subsite_link = get_blog_details( $subsite_id )->siteurl;
echo '<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '">' . $subsite_name . '</a></li>';
}
echo '</ul>';
}
}
add_action( 'wpmu_before_header', 'wpmu_list_sites' );
function wpmu_list_sites() {
$subsites = get_sites();
if ( ! empty ( $subsites ) ) {
echo '<section class="subsites-container">';
echo '<ul class="subsites">';
foreach( $subsites as $subsite ) {
$subsite_id = get_object_vars( $subsite )["blog_id"];
$subsite_name = get_blog_details( $subsite_id )->blogname;
$subsite_link = get_blog_details( $subsite_id )->siteurl;
echo '<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '">' . $subsite_name . '</a></li>';
}
echo '</ul>';
echo '</section>';
}
}
add_action( 'wpmu_before_header', 'wpmu_list_sites' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment