WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Blog list (3 posts)

  1. randinicole
    Member
    Posted 2 years ago #

    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

    http://thejudens.com/eric/2009/08/wordpress-mu-list-blogs/

    <?php if(is_front_page()){?>
        <h1>Blog Directory</h1>
    
    <?php
        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

  2. 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.

  3. Big Bagel
    Member
    Posted 2 years ago #

    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:

    $blog_details->post_count

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags