WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

WPMU List All Blogs Widget

This code is the code needed to create a widget to show a list of all blogs. It is dependent on the plug-in List-All, that should be installed first. Create a blank text file named widget_list_all.php in your plugins folder, add the following php code. You should then be able to activate the List All plugin and the List-All-Blogs Widget on the plugins tab. Then look over in the presentation/widgets tab and you should have a new widget named List All Blogs Widget.

<?php
/*
Plugin Name: List-All-Blogs Widget
Plugin URI: http://codex.wordpress.org/WPMU_List_All_Blogs_Widget
Description: Creates a list of all blogs on a WPMU site as a widget, conversion from previous version based on code in http://www.erik-rasmussen.com/blog/2006/11/30/widgetize-anything/
Author: Unknown - last edited Angelo Bertolli
Author URI: http://codex.wordpress.org/WPMU_List_All_Blogs_Widget
Version: 0.0.2
*/

// $show_blog_list_widget = true;  // Uncomment this if you want this widget available for all users

function widget_list_all_blogs_init() {
        if ( !function_exists('register_sidebar_widget') )
                return;


        function widget_list_all_blogs($args) {
        extract($args);

        if(function_exists(list_all_wpmu_blogs)) {
                 echo $before_widget;

                 echo $before_title . 'All Blogs' . $after_title;
                        echo "<ul>\n";
                        list_all_wpmu_blogs('100', 'name', '<li>', '</li>', 'updated');
                        echo "</ul>\n";
                 echo $after_widget;
        }
                else
                {
                 echo "Error - function  list_all_wpmu_blogs not found";
        }
        }


    if ( function_exists('wp_register_sidebar_widget') ) // fix for wordpress 2.2.1
      wp_register_sidebar_widget(sanitize_title('List All Blogs' ), 'List All Blogs', 'widget_list_all_blogs', array(), 1);
    else
      register_sidebar_widget('List All Blogs', 'widget_list_all_blogs', 1);
}

if (get_blog_option(1,'siteurl') == get_settings('siteurl')) // Widget available for the main blog
        $show_blog_list_widget = true;

if ($show_blog_list_widget)
        add_action('plugins_loaded', 'widget_list_all_blogs_init');

?>