Can't set Global Var
-
Hi all,
I can’t get my head around a rather simple task, I’m afraid.
I’m creating a dual language website. For incompatibility reasons with a must have plugin (dsIDX), I can’t use WPML or qTranslate.
So I want to change wp_nav_menu myself. I have 2 menus (1MainEN = english and 1MainDE = german)I have a simple form in a sidebar widget, where the user can chose the language:
<form method="POST" action=""> <select name="IMmenuSelection" onchange='this.form.submit()'> <option>English</option> <option>Deutsch</option> </select> </form>
In the child themes functions.php I defined a global var and get and set functions
global $IM_menu; $IM_menu = "1MainEN"; // the function to get the global variable function IM_menu_get_var() { global $IM_menu; return $IM_menu; } // the function to set the global variable function IM_menu_set_var($IMnew_value) { global $IM_menu; $IM_menu = $IMnew_value; }
in the child themes header.php I try to catch the users choice and set the global var $IM_menu accordingly.
<?php $IM_post_language = $_POST['IMmenuSelection']; //what did the user select if( $IM_post_language == "Deutsch") { IM_menu_set_var('1MainDE'); } if( $IM_post_language == "English") { IM_menu_set_var('1MainEN'); } ?> <?php wp_nav_menu( array('container' => 'div', 'container_class' => 'menu-wrapper', 'container_id' => 'main-superfish-wrapper', 'menu_class'=> 'sf-menu', 'theme_location' => 'main_menu', 'menu' => IM_menu_get_var() ) ); ?>
It reacts when the user selects a different language (DE) and shows the right menu (defaults to Home in the new menu), but once the user selects a different entry in the new menu (DE), it switches back to the English Menu – not recognizing the global var $IM_menu.
I’m out of ideas, as I try to get this straight for too long — tunnel view!
You can see the site here https://realtyswflorida.comAny help is more than welcome!
[Moderator Note: No bumping, thank you.]
- The topic ‘Can't set Global Var’ is closed to new replies.