Support » Networking WordPress » Global Navigation Strip Plugin for all Websites in Multisite – Rocket Science!?

  • cowlishaw

    (@cowlishaw)


    I didn’t think this would be nuclear rocket science but I simply cannot locate a plugin or simple solution that would allow me to create a universal drop down navigation menu between all of my websites in a multisite installation.

    I was using this:
    https://wordpress.org/support/view/plugin-reviews/spyr-bar

    Can someone please direct me to a simple and straight forward solution that is relatively easy to set up or am I out of luck?

    Why am I using Multisite? Because I’m a geek and wanted to control a WordPress Network! 😉

    Nate

Viewing 1 replies (of 1 total)
  • Zane Matthew

    (@zanematthew)

    Hi Nate,

    Thanks for using WordPress, and kudos for setting up Multisite.

    …create a universal drop down navigation menu between all of my websites in a multisite installation

    What exactly are you wanting to populate the menu with? pages for all sites, all the site names, etc.?

    It may be hard to find a plugin, because this is a fairly unique request, also this isn’t fully recommended as there are performance issues when getting data from all your sites, while on another site. I’ve listed out the steps involved, you can place this in your functions.php file, or use it as a plugin. However I have not tested this, and I would strongly recommend using some form of caching.

    /**
     * Retrieve a list of ALL sites in your network.
     * https://developer.wordpress.org/reference/functions/wp_get_sites/
     */
    $sites = wp_get_sites();
    
    /**
     * Assign an array to be used to store all site pages on the network
     * @var array
     */
    $all_pages_on_network = array();
    
    /**
     * In order to retrieve content from a site, while on another site
     * you'll need to switch to that site, hence the switch_to_blog()
     * function.
     *
     * Iterate over each site, switching to said site and retrieving ALL
     * pages. See https://codex.wordpress.org/Function_Reference/switch_to_blog
     * for a list of Params for get_pages();
     */
    foreach( $sites as $site ){
    
        switch_to_blog( $site['ID'] );
        $all_pages_on_network[] = get_pages();    
    
    }
    
    /**
     * Here you'll want to build your markup as desired
     */
    echo '<select>';
    foreach( $all_pages_on_network as $all_page_on_network ){
        echo "<option>Name: {$all_page_on_network['post_title']} ID: {$all_page_on_network['ID']}</option>";
    }
    echo '</select>';

    Let me know if this helps, and good luck.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.