Posted By

juanrossi on 11/18/10


Tagged

menu php wordpress wp sites mu multisites


Versions (?)

Get list of blogs from Wordpress Multisites / MU in a list


 / Published in: PHP
 

URL: http://www.vulsai.com

This code is usefull for getting the list of Wordpress Sites from Multisite without sending each user id.

  1. // Query for getting blogs
  2. $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A );
  3.  
  4. // put it in array
  5. foreach ( (array) $blogs as $details ) {$blog_list[ $details['blog_id'] ] = $details;}
  6. unset( $blogs );
  7. $blogs = $blog_list;
  8.  
  9. // if is valid array
  10. if (is_array( $blogs ) ){
  11. echo '<ul>';
  12. $array= array();
  13. // reorder
  14. $array= array_slice( $blogs, 0, count( $blogs ) );
  15. for($i=0;$i<count($array);$i++){
  16. // get data for each id
  17. $blog = get_blog_details( $array[$i]['blog_id'] );
  18. // print it
  19. echo '<li><a href="'.$blog->siteurl.'">'.$blog->blogname.'</a></li>';
  20. }
  21. echo '</ul>';
  22. }

Report this snippet  

You need to login to post a comment.