The MU forums have moved to WordPress.org

Multi-Blog navigation (2 posts)

  1. ancawonka
    Member
    Posted 14 years ago #

    Hello,

    I'm working on an WPMU intranet. We are using individual blogs to create site areas, which are then published and maintained by different user groups within the organization.

    However, the entire intranet needs to have a unified look and feel, and a header (w/ navigation) that is shared by all the blogs. In order to accomplish this, each blog has a link category (site-navigation) that's set up to store the header links for each area. Links that show up in the header can be to a WP page, an application, or pretty much anything, really, so it seemed to me that using a link category was the best way to go.

    Here's a function I wrote to extract the links from the database directly.

    function sitewide_navigation(){
    
    	global $wpdb;
    
    	// the ID of the blogs to include in the nav.   the order specified here determines
    	// the order of display.
    	$blogs = array("2", "7","6", "3", "4");  
    
    	//Get the list of blog names.  These appear at the top as the tab names
    
    	$query = "";
    	$num_blogs = sizeof($blogs);
    	for ($i = 0; $i < $num_blogs; $i++){
    		$wp_options_table = "wp_" . $blogs[$i] . "_options";
    		$query .= "(select '$blogs[$i]' as 'blog_id', option_value as 'blogname' from $wp_options_table where option_name='blogname')";
    		if ($i < ($num_blogs - 1)){
    			$query .= ' union ';
    		} else {
    			$query .= ';';
    		}
    	}
    
    	echo $query . "<br />";
    
    	$bloginfos = $wpdb->get_results($query, ARRAY_A);
    	$blognames = array();
    
    	if ($bloginfos){
    		foreach ($bloginfos as $bloginfo){
    			$blognames[$bloginfo['blog_id']] = $bloginfo['blogname'];
    		}
    	}
    
    	// Get the blog URL's.  Unfortunately, this has to be done in a separate query.
    	// The Blog Name is stored in an options table, and the blog URL is in the wp_blogs table.
    
    	$bloglinks = array();
    
    	$query = 'select blog_id, path from wp_blogs';
    
    	$bloginfos2 = $wpdb->get_results($query, ARRAY_A);
    
    	foreach ($bloginfos2 as $bloginfo){
    		$bloglinks[$bloginfo['blog_id']] = $bloginfo['path'];
    	}
    
    	// Finally, get the list of links for each blog.
    
    	$query = "";
    	$num_blogs = sizeof($blogs);
    	for ($i = 0; $i < $num_blogs; $i++){
    		$wp_links_table = "wp_" . $blogs[$i] . "_links";
    		$wp_term_rel_table = "wp_" . $blogs[$i] . "_term_relationships";
    		$wp_taxonomy_table = "wp_" . $blogs[$i] . "_term_taxonomy";
    		$wp_terms_table = "wp_" . $blogs[$i] . "_terms";
    		$query1 = '(select "' . $blogs[$i] . '" as "blog_id", link_url, link_name, link_rating from ' . $wp_links_table . ' where link_id in (select object_id from ' . $wp_term_rel_table . ' where term_taxonomy_id=(select term_taxonomy_id from ' . $wp_taxonomy_table . ' where term_id=(select term_id from ' . $wp_terms_table .' where slug=\'site-navigation\'))) order by link_rating)';
    		if ($i < ($num_blogs - 1)){
    			$query1 .= ' union ';
    		} else {
    			$query1 .= ';';
    		}
    		$query .= $query1;
    	}
    
    	//echo $query . "<br />";
    
    	echo '<ul class="menu"><li class="tab tab-home"><a href="/">Home</a></li>';
    
    	// Each blog has its own "tab" and then, if there is content below, it
    	// will create a drop-down.
    	$results = $wpdb->get_results($query, ARRAY_A);
    
    	if ($results){
    		$cur_blog = 0;
    		foreach ($results as $link_item){
    			$blog_id = $link_item['blog_id'];
    			if ($blog_id != $cur_blog){
    				if ($cur_blog > 0){  //finish off the previous submenu
    					?>
    					</li></ul>
    					<?
    				}
    				?>
    				<li class="tab tab-<?php echo($blog_id) ?>"><a href="<?php echo($bloglinks[$blog_id]); ?>" alt="<?php echo ($blognames[$blog_id]); ?>"><?php echo ($blognames[$blog_id])?></a><ul class="submenu">
    				<?
    				$cur_blog = $blog_id;
    			}
    			?>
    			<li class="item"><a href="<?php echo($link_item['link_url']) ?>"><?php echo($link_item['link_name']) ?></a></li>
    			<?
    		}
    	}
    
    	echo '</li></ul></ul>'; //close the last submenu and the menu class
    }

    My next step is to make use of the cache to store the output menu, since this will be used man, many times... But I thought you might find this useful in your own WPMU hacking.

  2. Synternet Strategies
    Member
    Posted 14 years ago #

    Hi anca,

    Sounds like you're trying to set up essentially the same site structure we are. I've posted this elsewhere but perhaps you have an insight into how to do this. Any input would be highly appreciated. :-)

    For optimization and organization reasons we are setting up our site as a main landing page http://www.synternet-strategies.com with subdomains and pages within each subdomain

    http://consulting.synternet-strategies.com
    Keyword Analysis
    Keyword Tracking
    Governance
    Standards
    Lead Generation etc.

    http://whitepapers.synternet-strategies.com
    Keyword Analysis
    Keyword Tracking
    Governance
    Standards
    Lead Generation etc.

    etc.

    What we would like to do is set up the navigation so that it is both global across all pages and subdomains and dynamically generated whenever a new page or or a new subdomain is set up.

    Thanks,

    Douglas Gibbens
    Synternet Strategies

About this Topic

  • Started 14 years ago by ancawonka
  • Latest reply from Synternet Strategies