admin管理员组文章数量:1122832
I'm trying to add language option to my website. I've coded my theme and I need to show the web in three different languages. I've got the little flags and I've managed to pass a php variable with the language it's selected. With that variable I've made a if for the wp_nav_menu assignment in the header.php. It works actually. When I change the language the correct menu in the correct language comes up. The problem is that when I hit in a menu item and the selected page opens the menu is gone. Disappears. Can anybody help me, plase? Here is the code I use.
In header.php
if ($language == 'en') {
wp_nav_menu(array(
'theme_location' => 'eng',
'container_class' => 'main-nav',
'container' => 'nav'
));
} else if ($language == 'de') {
wp_nav_menu(array(
'theme_location' => 'ger',
'container_class' => 'main-nav',
'container' => 'nav'
));
} else {
wp_nav_menu(array(
'theme_location' => 'esp',
'container_class' => 'main-nav',
'container' => 'nav'
));
}
And in the functions.php
add_theme_support ('menus');
//Create Nav Menu
if (function_exists ('register_nav_menus')) {
register_nav_menus (array(
'esp' => 'Spanish menu',
'eng' => 'English menu',
'ger' => 'Deutsch menu'
));
}
And the html for the flag link in header.php
<li><a href="http://localhost/wordpress/inicio?language=es" ><img src="http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG" width="18" height="12" onmouseover="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espH.PNG'" onmouseout="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG'"></a></li>
I'm trying to add language option to my website. I've coded my theme and I need to show the web in three different languages. I've got the little flags and I've managed to pass a php variable with the language it's selected. With that variable I've made a if for the wp_nav_menu assignment in the header.php. It works actually. When I change the language the correct menu in the correct language comes up. The problem is that when I hit in a menu item and the selected page opens the menu is gone. Disappears. Can anybody help me, plase? Here is the code I use.
In header.php
if ($language == 'en') {
wp_nav_menu(array(
'theme_location' => 'eng',
'container_class' => 'main-nav',
'container' => 'nav'
));
} else if ($language == 'de') {
wp_nav_menu(array(
'theme_location' => 'ger',
'container_class' => 'main-nav',
'container' => 'nav'
));
} else {
wp_nav_menu(array(
'theme_location' => 'esp',
'container_class' => 'main-nav',
'container' => 'nav'
));
}
And in the functions.php
add_theme_support ('menus');
//Create Nav Menu
if (function_exists ('register_nav_menus')) {
register_nav_menus (array(
'esp' => 'Spanish menu',
'eng' => 'English menu',
'ger' => 'Deutsch menu'
));
}
And the html for the flag link in header.php
<li><a href="http://localhost/wordpress/inicio?language=es" ><img src="http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG" width="18" height="12" onmouseover="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espH.PNG'" onmouseout="this.src='http://localhost/wordpress/wp-content/themes/wordpressthemeAPI2/img/espflag.PNG'"></a></li>
Share
Improve this question
asked Oct 14, 2013 at 12:35
MarkMark
112 bronze badges
2 Answers
Reset to default 0I am not sure that you have provided enough information for solving this issue, it is unclear why and when your menu disappears and under what conditions.
I am not sure why you are registering all the menus, when you probably need one.
I can only advise you to use a plugin that manages languages on the site, there are many options that will probably make this a bit easier for you.
If you provide more information or a test url, I will be happy to take another look
Good luck,
Thanks for your interest. Actually what happens is that when you hit on a emnu button it takes you to the correct page, but the menu changes to the spanish language wich, I supose looking at the code, is set sort of default.
Here you have a link to have a look to what I'm trying to do. Thank you!
http://ibizaonlinerentals.com/newweb/
本文标签: Multiple languages menus problem
版权声明:本文标题:Multiple languages menus problem 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288437a1928096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论