Created
October 21, 2014 11:15
-
-
Save lislis/8caf6dae4065a85d689e to your computer and use it in GitHub Desktop.
Get a list of all blogs in a Wordpress mulisite installation with an image for each blog
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
/* | |
* This is kind of a hack but it gets the job done. | |
* Paste this in your theme's functions.php | |
* The function returns an array of all blogs in the multisite network. | |
* For the image I make use of Wordpress' custom header functionality | |
*/ | |
function get_all_blogs() { | |
$blogs = array(); | |
$count = 0; | |
$blog_list = get_blog_list( 0, 'all' ); | |
foreach ($blog_list AS $blog) { | |
$blogs[$count] = array(); | |
$blogs[$count]['id'] = $blog['blog_id']; | |
$blogs[$count]['url'] = get_blog_option( $blog['blog_id'], 'siteurl' ); | |
$blogs[$count]['title'] = get_blog_option( $blog['blog_id'], 'blogname' ); | |
$blogs[$count]['text'] = get_blog_option( $blog['blog_id'], 'blogdescription' ); | |
// to access each blogs global settings | |
switch_to_blog($blogs[$count]['id']); | |
$data = get_theme_mod('header_image_data'); | |
$attachment_id = $data->attachment_id; | |
$image = wp_get_attachment_image_src( $attachment_id, 'your_custom_image_size'); | |
$blogs[$count]['image'] = $image[0]; | |
restore_current_blog(); | |
$count = $count + 1; | |
} | |
return $blogs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment