• Resolved randinicole


    Hi 🙂 I have wordpress+Mu installed and things are good, however I am trying to list all the blogs in the sidebar, I am using the following code but do not know where to “add to” the info so I can have them display the post count next to the list and if I could have them go in alphabetical order. Here is the code, its taken from here. Thanks for your help


    <?php if(is_front_page()){?>
        <h1>Blog Directory</h1>
        global $wpdb;
        $query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != '1' AND archived != '1' AND deleted != '1' AND public = '1' AND blog_id != '1' ORDER BY path";
        $blogs = $wpdb->get_results($query);
        echo '<ul>';
        foreach($blogs as $blog){
            $blog_details = get_blog_details($blog->blog_id);
            echo '<li><a href="'. $blog_details->siteurl .'">' . $blog_details->blogname .'</a></li>';
        echo '</ul>';

    I think I might have it figured out with a plugin but I would rather hardcode it into the theme

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Halfelf Rogue & Plugin Review Team Rep

    I know you said NOT a plugin but you can LOOK at this one http://wordpress.org/extend/plugins/diamond-multisite-widgets/ and see the code he uses to do exactly that.

    I think Diamond MultiSite Widgets uses switch_to_blog(), which works but has been deprecated. It’s been a few days so you most likely already worked something out, but I’ll give it a go.

    Your $blog_details variable should already contain the post count for each blog:


    As far as ordering by site name, I don’t think the name of each blog is stored together in any table, so using ORDER BY in the query is probably out. You could order by domain with ORDER BY domain, but sorting by blog name might require adding another loop just to add the blog name to each object/array in $blogs, then sorting.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Blog list’ is closed to new replies.