Showing List of recently Created blogs on wordpress Mu

Jotted by brajesh on January 5, 2009

Working on one of my client’s project recently,I found myself looking for some code to show list of recently created blogs on a wordpress Mu website.

After googling for around 15 minutes,I could not find anything to help me.
Finally,I decided to write the code myself.

The code is pretty straight forward,you may include it directly in your theme or use as a plugin.
Here goes the snippets of code dissected.

<?php
/*Fetch an array of $number_blogs most recently created blogs
**@number_blogs :The number of most recently created blogs you want to show.
*/
function get_recent_blogs($number_blogs=5)
{
  global $wpdb;
  $blog_table=$wpdb->blogs;
/*fetch blog_id,domain,path from wp_blogs table ,where the blog is not spam,deleted or archived order by the date and time of registration */
  $query="select blog_id,domain,path from $blog_table where public='1' and archived='0' and spam='0' and deleted='0' order by registered desc limit 0,$number_blogs";
 
  $recent_blogs=$wpdb->get_results($wpdb->prepare($query));
 
return $recent_blogs;
 
 }
?>

It returns an array of objects having the fields blog_id,domain,path. So now,if you are like me, you may be interested in showing a bulleted list(or simply a list of these all the blogs recently created ),you may do following

<ul class="recent-blogs">
<?php $recent_blogs=get_recent_blogs(5);
	foreach($recent_blogs as $recent_blog):
		$blog_url="";
		if( defined( "VHOST" ) && constant( "VHOST" ) == 'yes' )
			$blog_url="http://".$recent_blog->domain.$recent_blog->path;
		else
		$blog_url="http://".$recent_blog->domain.$recent_blog->path;
	$blog_name=get_blog_option($recent_blog->blog_id,"blogname");
	?>
<li>
<h3><a href="<?php echo $blog_url;?>"><?php _e( $blog_name)?> </a></h3>
<span><?php echo $blog_name?></span>
</li>
<?php endforeach;?>
</ul>

That’s It.we are done.Well ,to make it more easy,I have created another function show_recent_blogs which has a prototype like following

<?php
function show_recent_blogs($number_blogs=5,$description=true)
?>

It will output similar to the above code,but if you call it like

<ul class="recent-blogs">
<?php
/*here first argument is the number of blogs you want to show */
 
show_recent_blogs(5,false);
?>
</ul>

It will not show the description.
You may download the whole file as a plugin here and Can drop it in your wp-content/mu-plugins folder or include in your themes functions.php.
Here is a screen shot from my test blog
recent-blog-list

Well,you may have a look at my template where I experimented this on the site http://clients.wpmudemo.com/motionsblogg
Have a look at the bottom of the right sidebar.

And here is the Plugin for download.List recently Created blogs (196)

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]
If you enjoyed this post, make sure you subscribe to my RSS feed!
Grab my other free plugins here at wordpress Plugins repository.
We will keep coming with more informative tips,tricks,tutorials to keep you updated with wordpress/buddypress/wordpress mu regularly.If you want to help us,You can ,by spreading the words.We provide free and premium plugins/support for wordpress Mu,buddypress at a very low cost (starting with $30 for 3 months membership).If you or anyone you know,needs some real good plugins/themes for their wordpress Mu/buddypress powered site, Please refer them to http://BuddyDev.com.We will highly appreciate your support and keep coming with more useful and free stuffs.


3 Responses to “Showing List of recently Created blogs on wordpress Mu”

  1. Hans says:

    This post was really awesome…

    Thank YOU :)

  2. [...] Or grab the plugin here. These snippets are courtesy of thinkinginwordpress.com [...]

  3. [...] BpDev Recently Created Blogs Widget: List the most recently created blogs on your wordpress mu/buddypress site Jotted by Brajesh Singh in Buddypress Free Plugins, WpMu Free Plugins on December 3, 2009 Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Now you can show a list of most recently created blogs on your wordpress mu/buddypres site. This is just an updated code and yeh New Widget, from my other post here on ThinkingInWordPress.com [...]


Leave a Reply


Get Adobe Flash playerPlugin by wpburn.com wordpress themes