Wordpress - How to list all network sites on one page

yes, small source for an template.

<ul class='postlist no-mp'>

<?php 
/**
 * Old version, change on 07/23/2013
 *
$blogs = $wpdb->get_results( 
    "SELECT blog_id,path FROM {$wpdb->blogs} 
    WHERE blog_id != {$wpdb->blogid} 
    AND site_id = '{$wpdb->siteid}' 
    AND spam = '0' 
    AND deleted = '0' 
    AND archived = '0' 
    order by blog_id", ARRAY_A
); 
 */

// get all blogs
$blogs = get_blog_list( 0, 'all' );

if ( 0 < count( $blogs ) ) :
    foreach( $blogs as $blog ) : 
        switch_to_blog( $blog[ 'blog_id' ] );

        if ( get_theme_mod( 'show_in_home', 'on' ) !== 'on' ) {
            continue;
        }

        $description  = get_bloginfo( 'description' );
        $blog_details = get_blog_details( $blog[ 'blog_id' ] );
        ?>
        <li class="no-mp">

            <h2 class="no-mp blog_title">
                <a href="<?php echo $blog_details->path ?>">
                    <?php echo  $blog_details->blogname; ?>
                </a>
            </h2>

            <div class="blog_description">
                <?php echo $description; ?>
            </div>

            <?php 
            query_posts( 'showposts=5' );
            if ( have_posts() ) :
                while( have_posts() ) :
                    the_post();
                    ?>
                    <div class="blog_post">
                        <div class="post_title">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        </div>
                        <div class="post_excerpt">
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                <?php endwhile; ?>
            <?php endif; 
            restore_current_blog();
            ?>
        </li>
<?php endforeach;
endif; ?>
</ul>

This will print out an unordered list of all public sites in a multisite network:

// $bcount = get_blog_count();
global $wpdb;
$blogs = $wpdb->get_results("SELECT * FROM $wpdb->blogs WHERE spam = '0' AND deleted = '0' and archived = '0' and public='1'");
if(!empty($blogs)){
    ?><ul class="menu"><?php
    foreach($blogs as $blog){
        $details = get_blog_details($blog->blog_id);
        if($details != false){
            $addr = $details->siteurl;
            $name = $details->blogname;
            if(!(($blog->blog_id == 1)&&($show_main != 1))){
                ?>
                <li class="menu-item<?php if($counter == get_current_blog_id()){ echo ' current-menu-item';}?>">
                    <a href="<?php echo $addr; ?>"><?php echo $name;?></a>
                </li>
                <?php
            }
        }
    }
    ?></ul><?php
}

Tags:

List

Multisite