如何在整个多站点网络中显示主站点的主菜单 [英] How to show primary menu of main site throughout multi-site network

查看:120
本文介绍了如何在整个多站点网络中显示主站点的主菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法切换了子站点的主导航菜单,以显示主站点的主导航.

I have managed to switch the primiary navigation menu of my subsites to show the main site primary navigation.

但是,它呈现在网站标题上方,而不是代码中指定的菜单位置.

However, it renders above the site-header instead of in the menu location dictated in the code.

这是我当前拥有的代码:

Here is the code I currently have:

    function wp_multisite_nav_menu() {
    global $blog_id;
}
    if ( ! is_multisite() || 2 == $blog_id ) {

    switch_to_blog( 1 );

    wp_nav_menu( array(
        'menu'              => 2,
        'fallback_cb'       => false,
        'menu_class'        => 'genesis-nav-menu',
        'theme_location'    => 'Primary Navigation Menu',

    )); 

    restore_current_blog(); 

}

我希望菜单被放置在主导航菜单"位置.

I was expecting the menu to be placed in the 'Primary Navigation Menu' location.

我错过了什么?

任何清晰度都值得赞赏.

Any clarity is appreciated.

更新

我设法在主菜单和辅助菜单中找到了答案,但是如何将站点标题更改为主站点标题和超链接?

I managed to figure it out for my primary and secondary menus however how do get the site title to change to the main site title and hyperlink?

这是我当前拥有的减去网站标题切换的代码

Here is the code I currently have minus the site title switch

//*Multisite global menus

//*Primary global menu
add_action('genesis_after_header', 'primary_menu_switch');
function primary_menu_switch() {
    global $blog_id;
    if ( ! is_multisite() || 2 == $blog_id ) {
    switch_to_blog( 1 );

    wp_nav_menu( array(
        'menu'              => 2,
        'fallback_cb'       => false,
        'menu_class'        => 'genesis-nav-menu',
        'theme_location'    => 'primary'
    ) );

    restore_current_blog(); 
}
}


//*Secondary global menu
add_action('genesis_header_right', 'secondary_menu_switch');
function secondary_menu_switch() {
    global $blog_id;
    if ( ! is_multisite() || 2 == $blog_id ) {
    switch_to_blog( 1 );

    wp_nav_menu( array(
        'menu'              => 17,
        'fallback_cb'       => false,
        'menu_class'        => 'genesis-nav-menu menu-primary responsive-menu',
        'theme_location'    => 'primary'

        ));         
    restore_current_blog(); 
}
}

//*Use main site title

function site_title_switch() {
    global $blog_id;
    if ( ! is_multisite() || 2 == $blog_id ) {

    switch_to_blog( 1 );



   restore_current_blog();  

}
} 

我是一个新手,所以请原谅黑客工作.

I am a complete novice so please excuse the hack job.

感谢您的见解.

推荐答案

这是对已更新问题的回答,而不是标题中的问题.

如果将其放在网络激活的插件中,则应该可以解决问题.阅读评论,看看它到底能做什么.根据您的主题制作方式,它可能不起作用.我是为二十一"主题而设计的.

This should do the trick, if you put it in a network activated plugin. Read the comments to see what it does exactly. It might not work depending on how your theme is made. I made it for the Twenty Eleven theme.

请记住,它将在所有使用路径'/'进行调用的位置(不仅在标头中)更改原始URL.

Keep in mind that it will change the home URL everywhere where it is called with a path '/', not only in the header.

add_filter( 'option_blogname', 'function_to_filter_the_blogname' );

// Changes the blog name of all sites that are not the main one to the name of the main one, only outside of the admin panel
function function_to_filter_the_blogname( $name ) {
    $main_site_id = get_main_site_id();
    if ( get_current_blog_id() != $main_site_id && ! is_admin() ) {
        return get_blog_option( $main_site_id, 'blogname' );
    }
    return $name;
}

add_filter( 'home_url', 'function_to_filter_the_home_url', 10, 4 );

// Changes the home URL of all sites that are not the main one to the home URL of the main one, only outside of the admin panel and only when the path is '/'
function function_to_filter_the_home_url( $url, $path, $orig_scheme, $blog_id ) {
    $main_site_id = get_main_site_id();
    if ( $blog_id != $main_site_id && ! is_admin() && '/' == $path ) {
        return get_blog_option( $main_site_id, 'home' );
    }
    return $url;
}

这篇关于如何在整个多站点网络中显示主站点的主菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆