I need to set up a site with about 5 menu pages in Chinese and 5 in English. Ideally, I’d have a “Top Toolbar” navigation with just “English” and “Chinese” selections. These selections would swap the “Main Navigation” setting (the one you establish under Theme Locations in the Appearences/Menu dialog) between two menus: “English Main Navigation” and “Chinese Main Navigation”.
Is there a php or .js hack to set the Main Navigation menu dynamically? For instance, suppose I have the “English” and “Chinese” links call different URL’s (was www.mysite.com\zh or www.misite.com\en), is there a spot in the php that could register a different navigation menu based on the different URL request?
Alternately, is there a way of filtering the Main Navigation pages by the requestor’s URL to display a different set of menu pages (say filtered by theme_location) based on whether the URL request?
I am fair at coding but new to php and Wordpress, so specific help to get me going would be much appreciated
[[LINK href="http://support.truethemes.net/attachments/token/x5ikz0l36fxvs5k/?name=tmp.docx"]][[/LINK]]
Fahad Murtaza answers:
OK
I have done that with [[LINK href="http://wordpress.org/extend/plugins/qtranslate/"]]qtranslate [[/LINK]]
See an example at http://simpleseo.nl
<?php _e('<!--:en-->This is english text or some variable and you can use php here<!--:--><!--:nl-->This is the dutch code<!--:-->')?>
My two languages are Dutch and English. You can create your own. qtranslate has fairly good documentation.
Fahad Murtaza comments:
I hope the above answers this questions as well.
<blockquote>Alternately, is there a way of filtering the Main Navigation pages by the requestor’s URL to display a different set of menu pages (say filtered by theme_location) based on whether the URL request? </blockquote>
Ivaylo Draganov answers:
Hello,
I've recently been tinkering with the same thing for a bilingual website. WordPress is notoriously poor at serving content multiple languages - there are a few plugins out there, but having tried them all I decided to code something simple myself. To switch the main navigation menu based on language you could do something like this (follow comments in the code):
[[LINK href="http://pastebin.com/G8FBAunQ"]]http://pastebin.com/G8FBAunQ[[/LINK]]
This setup relies on having the pages for each language under a master page for that language. And the master page should have the locale in the URL ( e.g. example.com/zh/chinese-page/ ). You need to have pretty permalinks enabled for this technique to work.
Ivaylo Draganov comments:
You can see it in action here:
http://youthtolerance.org/
There are some more things that I do on this site with the same approach - such as building the language switch and the home URL for each language.
ej_emman answers:
I am a little bit confuse what you really want to happen.
if your concern is to switch menu pages in wordpress
assuming you have already created menus in Appearance->menus.
Ex. If you have already created menus "English Main Navigation" and "Chinese Main Navigation".
To switch this two.. this is the code;
// your selection menu place it where you want to place
<form method="POST" action="">
<select name="myselection" onchange='this.form.submit()'>
<option>English</option>
<option>Chinese</option>
</select>
</form>
// if you want to switch menu pages. You must place it to the header or any location
// you want to place the menu navigation
<?php
if($_POST['myselection'] == 'English')
wp_nav_menu( array('container_class' => 'menu-header','menu' => 'English Main Navigation' ));
else if($_POST['myselection'] == 'Chinese')
wp_nav_menu( array('container_class' => 'menu-header','menu' => 'Chinese Main Navigation' ));
?>
But if you want to switch domain just use wp_redirect. Hope this helps
// But if you want to redirect to different domain
<?php
if($_POST['myselection'] == 'English')
wp_redirect( 'http://www.youEnglishdomain.com', 301 ); exit;
else if($_POST['myselection'] == 'Chinese')
wp_redirect( 'http://www.youChinesedomain.com', 301 ); exit;
?>