• Resolved vivateck

    (@khmohsin)


    Hi,
    I have installed WordPress 3.0.1 on my new site. I have multi site functionality but I am using the directory style for new blogs i.e. /blog1
    and /blog2 etc.
    I want to display a list of all the blogs created this way on my home page, or any other page, but not in the sidebar.
    I know buddy press can create a “blogs” page on our main site and there it displays all the blogs but i do not want to use buddy press.
    Can one point to me code that is required to pull a list of blogs that I have in my network.
    Thanks.

Viewing 15 replies - 1 through 15 (of 17 total)
  • can i get posts along with the list?

    For getting all the posts, you have to use a different plugin. Like I mentioned in the other thread you responded to.

    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/

    Hi Andrea,

    I am using same plugin for my website. But stuck up at the point where you need to add some loop to home page. to fetch all posts in that page.

    Basically i want to have a home page like wordpress.com. with latest updated post from various blogs.

    Regards,
    Sam.

    You do not need to add a loop anywhere. Just use a regular theme.

    How strange. I just followed the link that Andrea_r posted, and that plugin page appears to be broken. Instead of a download button, there’s just a red bar. Is anyone else seeing that?

    Yes, I see the same problem πŸ™ Can’t download the plugin.

    I just submitted the bug. Also, the menu tabs (Description, FAQ, etc.) are missing.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Advisor and Activist

    They’re mucking with the plugin database. It could be related to that. I’ll drop ’em a note (’em being ’em what’re mucking with the DB).

    Worked for me just now.

    Yep. Looks like it’s fixed.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Advisor and Activist

    Magic. Remember to thank Otto and tip your waiter.

    leopardo956

    (@leopardo956)

    Here’s a function that works with version 3.1

    function get_all_sites() {
    
    	global $wpdb;
    
    	// Query all blogs from multi-site install
    	$blogs = $wpdb->get_results("SELECT blog_id,domain,path FROM wp_blogs where blog_id > 1 ORDER BY path");
    
    	// Start unordered list
    	echo '<ul>';
    
    	// For each blog search for blog name in respective options table
    	foreach( $blogs as $blog ) {
    
    		// Query for name from options table
    		$blogname = $wpdb->get_results("SELECT option_value FROM wp_".$blog->blog_id ."_options WHERE option_name='blogname' ");
    		foreach( $blogname as $name ) { 
    
    			// Create bullet with name linked to blog home pag
    			echo '<li>';
    			echo '<a href="http://';
    			echo $blog->domain;
    			echo $blog -> path;
    			echo '">';
    			echo $name->option_value;
    			echo '</a></li>';
    
    		}
    	}
    
    	// End unordered list
    	echo '</ul>';
    }

    You might need to change the http:// or the database name based on your settings.

    @leopardo…thanks a bunch. I modified your function slightly to be a little more abstract.

    if(!function_exists('get_all_sites')){
      /**
       * Retrieves all multisite blogs
       *
       * @return array Blog IDs as keys and blog names as values.
       */
      function get_all_sites() {
    
        global $wpdb;
        $multisite = array();
        // Query all blogs from multi-site install
        $blogs = $wpdb->get_results("SELECT blog_id,domain,path FROM wp_blogs ORDER BY path");
    
        // Get primary blog
        $blogname = $wpdb->get_row("SELECT option_value FROM wp_options WHERE option_name='blogname' ");
        $multisite[1] = $blogname->option_value;
    
        // For each blog search for blog name in respective options table
        foreach( $blogs as $blog ) {
          // Get rest of the sites
          $blogname = $wpdb->get_results("SELECT option_value FROM wp_".$blog->blog_id ."_options WHERE option_name='blogname' ");
          foreach( $blogname as $name ) {
            $multisite[$blog->blog_id] = $name->option_value;
          }
        }
        return $multisite;
      }
    }

    Glad it helped. Thanks for building upon it.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘How to create a list of all multi-sites or blogs within one site’ is closed to new replies.