cialis online pharmacy generic xenical cheap cialis online cialis generic viagra online in canada buy cheap levitra online cialis without a perscription order viagra uk no prescription flagyl cheap generic levitra buying viagra in the uk cheap viagra approved cialis deltasone online buy viagra online without prescription non prescription cialis buy orlistat uk buy cialis in india prednisone 60 mg female viagra online buy viagra without prescription celebrex prescriptions buy cialis canada best prices viagra alternative to prednisone cheapest generic levitra levitra 5mg cheap viagra cialis on line buy xenical without prescription online accutane canadian health care prednisone no prescreption viagra online generic female viagra europe buy cialis low price cheap india viagra
wordpress

Build A WordPress Network Navigation Menu

WordPress 3.0 has allowed users to host multiple independent websites with just one feature called Multisite. It also lets you share settings, content, and code between websites within your network.

Kevin Leary has shared some of the hacks he did to perform the aforementioned abilities in one of his articles; one of them involves building a network navigation menu. Below is a snippet of the code:

Simply paste this in your theme’s functions.php file.

/** 

* Build a list of all websites in a network

*/

function wp_list_sites( $expires = 7200 ) {

if( !is_multisite() ) return false;

// Because the get_blog_list() function is currently flagged as deprecated

// due to the potential for high consumption of resources, we’ll use

// $wpdb to roll out our own SQL query instead. Because the query can be

// memory-intensive, we’ll store the results using the Transients API

if ( false === ( $site_list = get_transient( ‘multisite_site_list’ ) ) ) {

global $wpdb;

$site_list = $wpdb->get_results( $wpdb->prepare(‘SELECT * FROM wp_blogs ORDER BY blog_id’) );

// Set the Transient cache to expire every two hours

set_site_transient( ‘multisite_site_list’, $site_list, $expires );

}

$current_site_url = get_site_url( get_current_blog_id() );

$html = ‘

<ul id=”network-menu”>’ . “\n”;

foreach ( $site_list as $site ) {

switch_to_blog( $site->blog_id );

$class = ( home_url() == $current_site_url ) ? ” : ”;

$html .= “\t” . ‘

<li id=”site-‘ . $site->blog_id . ‘” ‘=”” .=”” $class=””><a href=”‘ . home_url() . ‘”>’ . get_bloginfo(‘name’) . ‘</a></li>

‘ . “\n”;

restore_current_blog();

}

$html .= ‘</ul>

<!–// end #network-menu –>’ . “\n\n”;

return $html;

}

You can use it in your theme by calling its wp_list_sites() function.

<?php 

// Multisite Network Menu

$network_menu = wp_list_sites();

if( $network_menu ):

?>

<div id=”network-menu”>

<?php echo $network_menu; ?>

</div>

<!–// end #network-menu –>

<?php endif; ?>

Cool, huh? Find out more about the rest of his WordPress hacks here!

Related Posts

Adding Instagram Badges to Your WordPress Profile

How to Create a Custom WordPress Registration Form with Flat UI

How to Create A Basic Hipster-Style Layout

How to Style Nav Links Using Floats With HTML5 and CSS3

1 Comment

  1. Create Website

    02.07.2012

    Thanks for those tips Keith, just what I was looking for.