2016-01-15 43 views
0

我目前有兩個通過後端創建的菜單。我需要根據地理位置激活菜單,我已經設置了默認貨幣。後端的菜單名稱是Main和Main International。下面是代碼:以編程方式設置Wordpress主菜單

function geo_client_currency($client_currency){ 
$userInfo = geoip_detect2_get_info_from_current_ip(); 

if ($userInfo->country->isoCode == 'US'){ 
    $client_currency = 'USD'; //currency code 
    } 
else { 
    $client_currency = 'INR'; 
} 

return $client_currency; 
} 

所以基本上我需要做的是設置在美國和主要國際主菜單爲美國以外的任何地方。我已經審查了食典,但不太清楚如何實現最簡單的方法

回答

0

在模板文件(如header.php)中可以這麼簡單嗎?

<?php 
    $userInfo = geoip_detect2_get_info_from_current_ip(); 
    if ($userInfo->country->isoCode == 'US'){ 
     wp_nav_menu(array('menu_id' => 1)); //Change 1 to be the Main ID 
    } else { 
     wp_nav_menu(array('menu_id' => 2)); //Change 2 to be the Main International ID 
    } 
?> 
+0

這似乎是它會工作,我怎麼能找回我的,因爲我在後臺創建的菜單菜單編號? – Erik

+1

劃痕,我繼續使用'菜單'=>'主'參數,謝謝! – Erik

0
<?php 

$userInfo = geoip_detect2_get_info_from_current_ip(); 

if ($userInfo->country->isoCode == 'US'){ 
    wp_nav_menu(array('theme_location' => 'nav-menu', 'menu'=> 'Main' , 'depth' => 3, 'container' => false, 'menu_class' => 'sf-menu', 'walker' => new thb_MegaMenu )); 
} else { 
    wp_nav_menu(array('theme_location' => 'nav-menu', 'menu'=> 'Main International' , 'depth' => 3, 'container' => false, 'menu_class' => 'sf-menu', 'walker' => new thb_MegaMenu )); //Change 2 to be the Main International ID 
} 

?>

相關問題