Get it All
Together

If you’re looking to maintain one contiguous system across a bunch of MU sites, you’ve probably figured out that its tough to keep a consistent look and feel directly through the system without some tweakage. Creating your own custom theme and making sure it’s the only one available makes the blogs look similar, but unfortunately, without a way to navigate back to the main portions of the system, looks are as far as it goes.

There are, I’m sure, many different ways to go about integrating all the various blogs into one system. For myself, I chose to define a list of pages on the root blog, each of which contains “syndicated” content from other blogs. The idea was similar to a newspaper’s sections on world events, local news, etc. I created an inline list at the top of all my blogs, each using the same set of pages, thereby fusing the whole package together. You can look to the top of this blog post to see what I mean: all the links in the “nav bar” thing point back to the root blog.

To do this, I created a function inside of the functions.php file that checked the pages available on the root blog and displayed them as a list. I have included this function below for your perusal:

function main_pages($exclude, $target_blog) {
global $wpdb;
$prefix = explode('_', $wpdb->prefix);
$target_table = $prefix[0].'_'.$target_blog.'_posts';
$exclude_list = ' AND `ID` != ';
$exclude_list .= implode(' AND `ID` != ', explode(',', $exclude));
$query = $wpdb->get_results("SELECT * FROM $target_table WHERE `post_type` LIKE 'page' $exclude_list AND `post_status` LIKE 'publish' ORDER BY `menu_order` ASC", ARRAY_A);
$output = '<ul>';
foreach($query as $page) {
$output .= '<li><a href="'.$page['guid'].'">'.$page['post_title'].'</a></li>';
}
$output .= '</ul>';
echo($output);
}

As you can see, the function takes two variables, the $target_blog and a comma-separated string of excluded pages called $exclude. Strictly speaking, it wasn’t necessary to include the $target_blog variable, but on the off chance that I might want/need to move things around, I included it.

One process which might be of interest to those of you new to WPMU is that of splitting up the prefix and appending a new blog ID. One of the curiously-difficult things about WPMU is querying information from across blogs: because $wpdb is set with one specific blog’s information, querying info from other blogs requires some jostling of the code to get the query to work right. My solution above is not the most elegant option, but it is effective.

I have toyed with the idea of creating a new database object for use on the website, naming it something along the lines of $pivot or something, but I’ve not yet had a chance to try it.  If you were to do such a thing, I’m not sure what if any effect it might have on the way the system works.  It may also be that it makes more sense to extend the current class than to just use it as-is.
When I know for sure, I’ll report back!