<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Social Ink &#187; wp_list_sites</title>
	<atom:link href="http://www.social-ink.net/tag/wp_list_sites/feed" rel="self" type="application/rss+xml" />
	<link>http://www.social-ink.net</link>
	<description>Web Design for Nonprofits and Small Businesses in New York City</description>
	<lastBuildDate>Thu, 16 May 2013 16:37:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>wp_get_multisites: WP3/WordPress 3: Generating dynamic list of multisites or replacing get_blog_list</title>
		<link>http://www.social-ink.net/blog/wp_get_multisites-wordpress3-wp3-generating-dynamic-list-of-multisites-or-replacing-get_blog_list</link>
		<comments>http://www.social-ink.net/blog/wp_get_multisites-wordpress3-wp3-generating-dynamic-list-of-multisites-or-replacing-get_blog_list#comments</comments>
		<pubDate>Wed, 23 Jun 2010 14:22:37 +0000</pubDate>
		<dc:creator>Yonatan Reinberg</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[custom functions]]></category>
		<category><![CDATA[multisite]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp3]]></category>
		<category><![CDATA[wp_list_sites]]></category>

		<guid isPermaLink="false">http://www.social-ink.net/?p=1490</guid>
		<description><![CDATA[<p><p>Social Ink: Web Design for Nonprofits and Small Businesses in New York City</p><p>Here at Social Ink we pride ourselves on WordPress expertise and one of our favorite features of Wordpress 3 is the "Multisite" feature, which weaves together WPMU's multi-blog features with WordPress' better plugin management, theme management and the like.  We'll be running a feature on ways to use this new Multisite feature, and today we present our first: How to list sites, or how to get a dynamic list of links (<em>with relative path</em>) of all your various sites (similar to <em>wp_list_categories</em>, or as a replacement for the deprecated <a href="http://codex.wordpress.org/WPMU_Functions/get_blog_list">get_blog_list</a>).  Think of it as a kind of <em>wp_list_sites</em>.</p></p><p><a href="http://www.social-ink.net">Social Ink - Web Design for Nonprofits and Small Businesses in New York City</a></p>]]></description>
				<content:encoded><![CDATA[<p>Social Ink: Web Design for Nonprofits and Small Businesses in New York City</p><p><strong>Update: Yes, this is a convoluted title. Sorry <img src='http://www.social-ink.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Who knows if people are searching for WP3, WordPress 3, WordPress 3.0, or its unfortunately search-unfriendly title &#8220;Thelonious&#8221;.</strong></p>
<p><a href="http://wordpress.org/development/2010/06/thelonious/">WordPress 3/WP3 is out</a>! Yes! There are tons of new features, tons of new <a href="http://www.andrewnacin.com/2010/03/22/deprecated-functions-and-wp_debug/">deprecated features</a> and tons of <a href="http://www.andrewnacin.com/2010/03/25/terminology-nightmare-blogs-sites-networks/">confusion</a>&#8230;</p>
<p>Here at Social Ink we pride ourselves on WordPress expertise and one of our favorite features of WordPress 3 is the &#8220;Multisite&#8221; feature, which weaves together WPMU&#8217;s multi-blog features with WordPress&#8217; better plugin management, theme management and the like.  We&#8217;ll be running a feature on ways to use this new Multisite feature, and today we present our first: How to list sites, or how to get a dynamic list of links (<em>with relative path</em>) of all your various sites (similar to <em>wp_list_categories</em>, or as a replacement for the deprecated <a href="http://codex.wordpress.org/WPMU_Functions/get_blog_list">get_blog_list</a>).  Think of it as a kind of <em>wp_list_sites</em>.</p>
<p><strong>Quick note</strong>: You should never use deprecated features if you can help it. WP3 actually still has <em>get_blog_list</em> in its bowels, but to rely on it would be dangerous for future updates. Better to use the newer functions WP3 provides.  Without future ado, here is our function, <em>wp_get_multisites</em>, which will retrieve a list of all your sites in WordPress 3, with many extra features, explained below the code.</p>
<pre><code>function wp_get_multisites($user = 1,$get_unwanted = false,$echo_it = true,$list_it = true,$ident = false,$class=&quot;&quot;) {
		//function to return a list of sites of all blogs on WP3 multisite. by yonatan reinberg/social ink - http://social-ink.net
		$output = &#039;&#039;; $myid = &#039;&#039;; 		
		if($list_it) { $output .= &#039;&lt;ul&gt;&#039;; }				
		$allsites = get_blogs_of_user($user, $get_unwanted);
			foreach ($allsites AS $blog) {
				if($ident)
					$myid = &#039;bloglist_&#039; . $blog-&gt;blogname;				
				if($list_it) 
					$output .= &#039;&lt;li&gt;&lt;a class=&quot;&#039;.$class.&#039;&quot; id=&quot;&#039;.$myid.&#039;&quot; href=&quot;&#039;.$blog-&gt;path.&#039;&quot;&gt;&#039;.$blog-&gt;blogname.&#039;&lt;/a&gt;&lt;/li&gt;&#039;;
				else
					$output .= &#039;&lt;a class=&quot;&#039;.$class.&#039;&quot; id=&quot;&#039;.$myid.&#039;&quot; href=&quot;&#039;.$blog-&gt;path.&#039;&quot;&gt;&#039;.$blog-&gt;blogname.&#039;&lt;/a&gt;&#039;;							
			}			
		if($list_it) { $output .= &#039;&lt;/ul&gt;&#039;; }
		if($echo_it)
			echo $output;
		else
			return $output;
	}<!--formatted--></code></pre>
<p>To begin, put this whole function in the <strong>functions.php</strong> file of your ACTIVE THEME. Since Multisite has support for various themes, this seems like a no-brainer but it might get you in the end.</p>
<p>Now, on to how to use it. Put the following wherever you want to display a list of your blogs:</p>
<pre><code>&lt;? wp_get_multisites() ?&gt;<!--formatted--></code></pre>
<p>That&#8217;s all! But wait, there&#8217;s many ways to customize it by passing it variables. The first is the user (use &#8220;1&#8243; for the superadmin, to get all blogs).  The second boolean is whether to get all the sites, or just the ones that are published/availale. The third is whether to to echo or to just return a string. The fourth is whether to create an unordered list or just return a string of the links. The fourth is whether you want special ids assigned to the individual links, and the 6th (!) is whether you&#8217;d like a class too&#8230;  Here is is in all its glory:</p>
<pre><code>&lt;? wp_get_multisites(1,true,true,false,false,&#039;testclass&#039;);  ?&gt;<!--formatted--></code></pre>
<p>Will return</p>
<pre><code>&lt;a class=&quot;testclass&quot; id=&quot;&quot; href=&quot;/&quot;&gt;socialinkdev&lt;/a&gt;&lt;a class=&quot;testclass&quot; id=&quot;&quot; href=&quot;/anothertest/&quot;&gt;anothertest!&lt;/a&gt;<!--formatted--></code></pre>
<p>Whereas</p>
<pre><code>&lt;? wp_get_multisites(1,true,true,true,true,&#039;mysites&#039;); ?&gt;<!--formatted--></code></pre>
<p>Will return</p>
<pre><code>&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;mysites&quot; id=&quot;bloglist_socialinkdev&quot; href=&quot;/&quot;&gt;socialinkdev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;mysites&quot; id=&quot;bloglist_anothertest!&quot; href=&quot;/anothertest/&quot;&gt;anothertest!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;<!--formatted--></code></pre>
<p><a href="http://www.social-ink.net/wp-content/uploads/plugins/ycyclista-v1.1.zip">Download the whole function here</a> (1k zip).  Any questions? Post em in the comments below &#8211; this really helped us with web design for nonprofits in New York City.</p>
<p><a href="http://www.social-ink.net">Social Ink - Web Design for Nonprofits and Small Businesses in New York City</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.social-ink.net/blog/wp_get_multisites-wordpress3-wp3-generating-dynamic-list-of-multisites-or-replacing-get_blog_list/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>
