使用主题安装功能设置多个菜单主题位置

时间:2014-02-05 09:22:47

标签: wordpress function menu themes

我有一个wordpress网站网络,其中一些需要安装具有附加功能的替代主题。原始主题有4个菜单位置,我想在安装新主题时设置它们。

我使用了这个:http://mharis.net/how-to-set-wordpress-menus-to-theme-locations/并且这个:https://wordpress.stackexchange.com/questions/15455/how-to-hard-code-custom-menu-items作为基础并拥有:

$locations = get_theme_mod( 'nav_menu_locations' ); // registered menu locations in theme
$menus = wp_get_nav_menus(); // registered menus

if($menus) {
foreach($menus as $menu) { // assign menus to theme locations
    if( $menu->name == 'ffh' ) {
        $locations['menu'] = $menu->term_id;
    } else if( $menu->name == 'ffh' ) {
        $locations['admin'] = $menu->term_id;
    } else if( $menu->name == 'ffh' ) {
        $locations['primary'] = $menu->term_id;
    } else if( $menu->name == 'ffh-guest' ) {
        $locations['visitor'] = $menu->term_id;
}}}
set_theme_mod('nav_menu_locations', $locations); // set menus to locations
}
 add_action('menu_location_register' );

但它不起作用。我很感激任何建议。

1 个答案:

答案 0 :(得分:-1)

$ locations = get_theme_mod('nav_menu_locations');

$ adveits_menus = wp_get_nav_menus();

if ( $adveits_menus ) {
    foreach ( $adveits_menus as $adveits_menu ) {
        if ( $adveits_menu->name == 'Front page EN' ) {
            $locations['menu-1'] = $adveits_menu->term_id;
        } else if ( $adveits_menu->name == 'Front page RU' ) {
            $locations['menu-1___ru'] = $adveits_menu->term_id;
        } else if ( $adveits_menu->name == 'Front page LT' ) {
            $locations['menu-1___lt'] = $adveits_menu->term_id;
        }
    }
}

set_theme_mod( 'nav_menu_locations', $locations );