【问题标题】:How to show primary menu of main site throughout multi-site network如何在多站点网络中显示主站点的主菜单
【发布时间】:2018-01-01 22:50:38
【问题描述】:

我已成功切换子站点的主导航菜单以显示主站点主导航。

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

这是我目前拥有的代码:

    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(); 

}

我希望将菜单放置在“主要导航菜单”位置。

我错过了什么?

任何清晰表示赞赏。

更新

我设法弄清楚我的主菜单和辅助菜单但是如何让网站标题更改为主网站标题和超链接?

这是我目前的代码减去网站标题开关

//*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();  

}
} 

我是个新手,所以请原谅我的黑客工作。

感谢您的见解。

【问题讨论】:

    标签: menu navigation share multisite genesis


    【解决方案1】:

    这是对更新问题的答案,而不是标题中的答案。

    如果你把它放在一个网络激活的插件中,这应该可以解决问题。阅读 cmets 以了解它的确切作用。它可能不起作用,具体取决于您的主题是如何制作的。我是为 21 点主题制作的。

    请记住,它会在任何使用路径“/”调用它的地方更改主 URL,而不仅仅是在标题中。

    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;
    }
    

    【讨论】:

    • 谢谢尼古拉。这就是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2018-06-20
    • 2015-05-30
    • 2021-04-16
    • 1970-01-01
    • 2021-10-24
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多