Wordpress multisite

Her på siden gemmer jeg diverse koder som benyttes på et WordPress multisite :-)

Vis samme menu på alle sites

<?php
global $blog_id;
$current_blog_id = $blog_id;

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

//output the WordPress navigation menu - incase of menu-sharing use this

wp_nav_menu(
  
//add your arguments here
);

//switch back to the current blog being viewed - before ending of the function

switch_to_blog($current_blog_id);
?>

Udskift wp_nav_menu(); med din menu ... måde at printe menuen på :-)

Kilde: https://wordpress.stackexchange.com/questions/24195/global-menus-made-fr...

List / menu til alle subsites

<?php
   
   
function wpmu_list_sites() {
   
   
$subsites = get_sites();
   
    if ( ! empty (
$subsites ) ) {
       
        echo
'<ul class="subsites">';

        foreach(
$subsites as $subsite ) {
       
           
$subsite_id = get_object_vars( $subsite )["blog_id"];
           
$subsite_name = get_blog_details( $subsite_id )->blogname;
           
$subsite_link = get_blog_details( $subsite_id )->siteurl;
            echo
'<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '">' . $subsite_name . '</a></li>';
   
        }
       
        echo
'</ul>';
   
    }
   
}
wpmu_list_sites();
?>