Show all Blog List for WordPress Multisite

Show all Blog List for WordPress Multisite

In this post, i want to share about “how to show our WordPress Multisite list, using Name of that website, and linked to each own url”.

Continuing my previous learning about WordPress multisite, i want to make all of my site getting indexed quickly by linking all of them, and put all of my site url in my theme footer. The “usual ways” is add it manually, but when we have more than 100 site??? are you sure to add it manually??

So, after long searching at google, wordpress codex, stackoverflow and all other site, finally i found a ways. In this case, we create a functions to call and listing our WordPress Multisite list, and then call it at footer, or maybe you can call it at sidebar.

wordpress-multisite

Here is the Functions that should be add :

if(!function_exists('get_all_sites')){
function get_all_sites() {
	global $wpdb;
// Query all blogs from multi-site install
	$blogs = $wpdb->get_results("SELECT blog_id,domain,path FROM wp_blogs where blog_id > 1 ORDER BY path");
// Start unordered list
	echo '<ul>';
// For each blog search for blog name in respective options table
	foreach( $blogs as $blog ) {
 
// Query for name from options table
		$blogname = $wpdb->get_results("SELECT option_value FROM wp_".$blog->blog_id ."_options WHERE option_name='blogname' ");
		foreach( $blogname as $name ) { 
 
// Create bullet with name linked to blog home pag
			echo '<a href="http://';
			echo $blog->domain;
			echo $blog -> path;
			echo '">';
			echo $name->option_value;
			echo '</a> | ';
		}
	}
 
// End unordered list
	echo '</ul>';
}
}

After modify the functions.php file and save it, you can call this script using this thing below :

<?php get_all_sites(); ?>

Once again, you can put this calling script at footer, or sidebar, or anyplace you desire.

Enjoy, and have a nice try

Facebook comments:

Leave a Reply

Your email address will not be published. Required fields are marked *


eight − six =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

AutoBlog Theme located at Indonesia , Malang, East Java . Reviewed by 98 customers rated: 4.4 / 5