I recently had to make a list of all the active blogs for the university’s blog site running WordPress MU. Here’s the code to do so:
Blog Directory
You’ll notice the query is set to filter out blogs that are marked as archived, spam, private. Also, it hides the main blog from the list.
UPDATE: As posted in the comments by Brad, you can sort these in alphabetical order by the site name by using the following code:
Great solution! Thanks for sharing your knowledge. Where do you insert this code
– which .php file?
– which line?
Sorry not really php litterate
Thanks,
Guy-Michel,
It depends on where you are wanting this to show. When I used it, we placed it on the index page of the site, so it was in index.php in our theme files.
I hope that helps!
Eric
what is?
echo '<a>siteurl .'">' . $blog_details->blogname .'';
Motto,
The code is making a list of links. siteurl is a link to each individual blog. $blog_details->blogname is pulling the blog title from the general settings page.
Eric
This did not work for me. I think you have a typo in your code but I am no PHP programmer. Does this rely on any plugins?
Matt,
Can you be a little more specific on what "did not work"? Have you tried enabling WP_DEBUG to see what errors you received?
Eric
Guess there have been some typo in one of the lines:
the line
echo '<a>siteurl .'">' . $blog_details->blogname .'';
need to become
echo '<a>siteurl .'">' . $blog_details->blogname .'';
hmm, the engine is filtering the characters, will try to write it better:
replace line
echo '<a>siteurl .'">' . $blog_details->blogname .'';
with line
echo '<a href="'.$blog_details->siteurl .'">' . $blog_details->blogname .'';
hope this time will be displayed correctly
Simone,
Thanks, I must have lost part of it while editing my post. I've edited the post and it shows correctly now.
Thanks,
Eric
You can not believe how long ive been looking for something like this. Through 9 pages of Yahoo results and couldnt find anything. One search on Bing. There this is…. Really have to start using it more often!
First of all thanks so much for making this available, it saved me some time for sure. I found that the php wouldn't run until I took the curly brace out of the opening line of code and moved it down e.g. {global…
BTW it works fine in wp3.0 with mu turned on.
Could this be done with posts and custom fields?
I have a review wordpessMU farm set up and we want the main page of the farm to show the latest post from each site with the custom fields. What do you think?
Thank you very much for this – been looking everywhere for an MU blog lister. Worked straight out of the box for MU 2.9.2.
I'm surprised there isn't a standard plugin for blog listing. Would seem to be saomething most MUs would require.
Hi – thanks – this is excellent – worked immediately on my site.
However – what other parameters are in blog_details? Is it possible to get blogowner, for example? I'd rather have a list of blog owners than the name of the blgo…
Chefpogo,
Here is a list of the fields from blog_details:
blog_id, site_id, domain, path, registered, last_updated, public, archived, mature, spam, deleted, lang_id, blogname, siteurl, post_count
Thank you for this code. I am use my wpmu blog
Thanks, Eric, a nice solution!
I use your code in a sidebar widget in my WP MU. (I have Exec-PHP plugin installed for the php code to be executed in posts, pages or widgets).
Lucian
This is fabulous! I have one small favor to ask. I am running MU 3.01. Can someone help me with the code to order the list by blog name? I'm not familiar enough with WP functions to know how to pull that off in the code.
Thank you so much for this code, it's working really well for my site! Much appreciated.
Melinda, I wanted the same thing, so we updated the code to show the blog list in alphabetical order by each blog's title. Below is the code.. one caveat: if you have two blogs with the exact same name, this will break.
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);
$blogList = array();
foreach($blogs as $blog){
$blog_details = get_blog_details($blog->blog_id);
$blogList[$blog_details->blogname] = $blog_details->siteurl;
}
ksort($blogList);
echo '';
foreach($blogList as $blogName => $blogUrl)
echo '<a href="'. $blogUrl .'" rel="nofollow">' . $blogName .'';
echo '';
}
?>
Work in 3.0.1?
Yes, it works in the latest version.
This is awesome. Thanks so much. Got it working with 3.1-alpha. Beats the the listall plugin.
Do you know how to create latest blog excerpt not just the blog list?
Thanks
Its is a very great tutorial & a very useful information for me,thanks for share
Great post.Thank you
Works like a charm here!
Beautiful code, simple but sure.
Thanks Eric!
obrigado. foi muito útil. 😉
Translated: Thank you. was very useful. 😉
Hello!!!!!!
ORDER BY path ?
How do I sort in alphabetical order?
Thanks!
Hello Fabricio,
The default is currently ordered by path. If you want to sort alphabetically, you can do as Brad had posted back in 2010. The code can be found here: https://gist.github.com/ericjuden/5583806
Hohoh!!! thank you very much =)
That way, I will continue my project WPMU.
I wish you a great day here in Brazil!!!
How to show the list of blog in horizontally 3 column with the logo of the blogs site and the url?