0
votes

How to create a single/main navigation menu having menu of all the network sites in wordpress multisite in the front/User side.

Like I have a page of administration in my mother site and also in the child sites, then how can I group a menu Admin with sub-menu administration of site1, administration of site2 and all...

I have tried, 2-3 codes like this

//store the current blog_id being viewed global $blog_id; $current_blog_id = $blog_id;

//switch to the main blog which will have an id of 1 switch_to_blog(1);

wp_nav_menu();

//output the WordPress navigation menu //wp_nav_menu( array('menu' => 'homepagemenu' ));

//wp_nav_menu( //array( 'theme_location' => 'homepagemenu' ) //); // //

//switch back to the current blog being viewed switch_to_blog($current_blog_id);

1

1 Answers

1
votes

You could tinker with the main function of this plugin: http://wordpress.org/plugins/hyper-admins/ however it adds a menu of your sites to the admin bar, not to the frontend.

First, you should create a site-specific-plugin, with a function to load the sites in your network:

function all_the_sites_menu() {
if ( ! is_super_admin() )
    return;

// Get all blog ids
global $wpdb;

$blog_ids = $wpdb->get_col( $wpdb->prepare( "
    SELECT blog_id 
    FROM {$wpdb->blogs}
    WHERE site_id = %d
    AND spam = '0'
    AND deleted = '0'
    AND archived = '0'
    ORDER BY registered DESC
", $wpdb->siteid ) );

    echo '<ul>'; //start the list

foreach ( $blog_ids as $blog_id ) {
    $blog_id = (int) $blog_id;
    $blog = get_blog_details( $blog_id );
    echo '<li><a href="http://' . $blog->siteurl . $blog->path .'">';
            echo $blog->blogname . '</a></li>';
}

    echo '</ul>'; //end the list

}

Then you could insert a tag into your theme to output the list, like this:

<?php all_the_sites_menu(); ?>