Last active
February 8, 2017 00:03
-
-
Save ryanshoover/5f3a0065d34cf666959ec9a5f3560774 to your computer and use it in GitHub Desktop.
Multisite Plugin for the WP Austin Meetup Group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WP-ATX MS Demo | |
Plugin URI: http://wpaustin.com | |
Description: Demoing WordPress Multisite Features | |
Version: 0.1 | |
Author: ryanshoover | |
License: GPLv2 or later | |
Text Domain: wpatxms | |
*/ | |
function wpatx_sites() { | |
// $sites = get_sites(); | |
$site_query = new WP_Site_Query( [ 'site__not_in' => get_current_blog_id() ] ); | |
$sites = $site_query->get_sites(); | |
$html = '<div class="sites">'; | |
foreach ( $sites as $site ) { | |
$title = get_blog_option( $site->blog_id, 'blogname' ); | |
$desc = get_blog_option( $site->blog_id, 'blogdescription' ); | |
$html .= '<div class="site">'; | |
$html .= '<h2>' . $title . '</h2>'; | |
$html .= '<p>' . $desc . '</p>'; | |
switch_to_blog( $site->blog_id ); | |
$post_query = new WP_Query( [ 'posts_per_page' => 3 ] ); | |
if ( $post_query->have_posts() ) { | |
$html .= '<ul>'; | |
while( $post_query->have_posts() ) { | |
$post_query->the_post(); | |
$post_title = get_the_title(); | |
$post_link = get_permalink( get_the_ID() ); | |
$html .= sprintf( '<li><a href="%s">%s</a></li>', $post_link, $post_title ); | |
} | |
$html .= '</ul>'; | |
} | |
wp_reset_postdata(); | |
$html .= '</div>'; | |
} | |
restore_current_blog(); | |
$html .= '</div>'; | |
return $html; | |
} | |
add_shortcode( 'wpatxsites', 'wpatx_sites' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment