<?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>Dusty Reagan &#187; WordPress MU</title>
	<atom:link href="http://dustyreagan.com/tag/wordpress-mu/feed/" rel="self" type="application/rss+xml" />
	<link>http://dustyreagan.com</link>
	<description>On Technology &#38; Entrepreneurship</description>
	<lastBuildDate>Thu, 15 Jul 2010 01:17:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Global page navigation accross WordPress MU blogs</title>
		<link>http://dustyreagan.com/global-page-navigation-accross-wordpress-mu-blogs/</link>
		<comments>http://dustyreagan.com/global-page-navigation-accross-wordpress-mu-blogs/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 09:57:48 +0000</pubDate>
		<dc:creator>Dusty Reagan</dc:creator>
				<category><![CDATA[Web & Software Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[WordPress MU]]></category>

		<guid isPermaLink="false">http://dustyreagan.com/?p=72</guid>
		<description><![CDATA[Here&#8217;s the scenario. You have a WordPress MU site with multiple blogs, but for whatever reason, you want every blog to have the same main navigation and pages. Your main site/blog hosts all of your pages. So how do you &#8230; <a href="http://dustyreagan.com/global-page-navigation-accross-wordpress-mu-blogs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the scenario. You have a WordPress MU site with multiple blogs, but for whatever reason, you want every blog to have the same main navigation and pages. Your main site/blog hosts all of your pages. So how do you go about creating a WordPress MU Theme that will use the navigation and pages from your main site/blog accross all of your blogs? Well, I&#8217;m here to tell you how I did it.</p>
<p>The WordPress Codex has a function called &#8216;wp_list_pages.&#8217; What I wanted to do is create a new function called &#8216;wp_list_main_pages.&#8217; So I simply searched my WordPress install and copied the &#8216;get_pages&#8217; and &#8216;wp_list_pages&#8217; functions and pasted them into my theme&#8217;s &#8216;functions.php&#8217; file. From here I made a few edits to these functions. To start with, I renamed them &#8216;wp_list_main_pages&#8217; and &#8216;get_main_pages.&#8217;</p>
<p>Below is the final code I&#8217;m using to display the main navigation accross blogs. I made notes in bold to help. Hope this is helpful to you Googling coders. <img src='http://dustyreagan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><strong>// You can use this function instead of 'wp_list_pages' in your theme</strong>
function wp_list_main_pages($args = '') {
	$defaults = array(
		'depth' =&gt; 0, 'show_date' =&gt; '',
		'date_format' =&gt; get_option('date_format'),
		'child_of' =&gt; 0, 'exclude' =&gt; '',
		'title_li' =&gt; __('Pages'), 'echo' =&gt; 1,
		'authors' =&gt; '', 'sort_column' =&gt; 'menu_order, post_title'
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	$output = '';
	$current_page = 0;

	// sanitize, mostly to keep spaces out
	$r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);

	// Allow plugins to filter an array of excluded pages
	$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));

	// Query pages.
	$r['hierarchical'] = 0;
	<strong>// Right here we call our new 'get_main_pages' function</strong>
	$pages = get_main_pages($r);

	if ( !empty($pages) ) {
		if ( $r['title_li'] )
			$output .= '&lt;li class="pagenav"&gt;' . $r['title_li'] . '&lt;ul&gt;';

		global $wp_query;
		if ( is_page() || $wp_query-&gt;is_posts_page )
			$current_page = $wp_query-&gt;get_queried_object_id();
		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);

		if ( $r['title_li'] )
			$output .= '&lt;/ul&gt;&lt;/li&gt;';
	}

	$output = apply_filters('wp_list_pages', $output);

	<strong>// This line is sloppy and needs improvement.
	// You have to remove the name of the blog your currently on from you global navigation.
	// I'm doing this the simplest but least scalable way here.</strong>
	$output = str_replace("pressroom/", "", $output);

	if ( $r['echo'] )
		echo $output;
	else
		return $output;
}

<strong>// This is essentially a private function</strong>
function &#038;get_main_pages($args = '') {
	global $wpdb;

	<strong>// This is the magic line.
	// Now when the SQL runs to pull your navigation pages, it'll use your main blogs ID.</strong>
	$wpdb-&gt;set_blog_id(1);

	<strong>// Notice here I call the original get_pages function and return the results</strong>
	$pages = get_pages($args);
	return $pages;
}
</pre>
<img src="http://dustyreagan.com/?ak_action=api_record_view&id=72&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://dustyreagan.com/global-page-navigation-accross-wordpress-mu-blogs/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
