The answers
Firstly, to add regional / multilingual support to wordpress, there is no better alternative to this plugin: http://wpml.org/ . It has a cost associated with this, but its not prohibitive (you pay for huge support).
Secondly, you cannot use $ _SESSION by default. WP has no analogues in design. However, there are tons of plugins and tutorials online to get this functionality.
Code property
There was no data entered in the original html form. It was a form that did not represent anything. This form has two views, which are called the same location . Thus, no matter which button is pressed, its value will be fed in the direction of $_POST['location'] .
<form action="<?php the_permalink(); ?>/home" name="region" method="post"> <div id="uk"> <input type="submit" name="location" value="UK" /> <img style="margin-bottom:10px;" src="<?php bloginfo('stylesheet_directory'); ?>/images/uk.png" width="259" height="160" alt="UK" /> <h1 style="color:black!IMPORTANT;">Enter United Kingdom site</h1> </div> <div id="world"> <input type="submit" name="location" value="World" /> <img style="margin-bottom:10px;" src="<?php bloginfo('stylesheet_directory'); ?>/images/world.png" width="258" height="160" alt="Rest of the World" /> <h1 style="color:black!IMPORTANT;">Enter Rest of the World site</h1> </div> </form>
Write a Wordpress action to process the message. Add this to your theme function file. look at http://php.net/manual/en/function.setcookie.php for setcookie files.
function set_location_cookie() { if(isset($_POST['location'])) { setcookie('location', $_POST['location'], time()+1209600); } } add_action('init', 'set_location_cookie');
Then, anywhere, you want to know the location:
<?php echo $_COOKIE["location"]; ?>
ADDITIONAL INFORMATION
First I clicked on the UK and it set the cookie, then I went back and clicked โWorldโ, but it did not copy the cookies with the world, it showed the UK again. Can cookies be wiped every time a different choice is made?
So, this is a problem with how cookies work at a technical level:
When the browser does this [requests the site], it will look on your computer at the cookie set by [your site]. If it finds a cookie, your browser will send all name-value pairs to the file on [server] along with the URL. If a cookie is not found, it will not send cookie data.
New cookie data is not initially sent, b / c it inst until the request is sent from your browser to the server so that the data of the new cookie is saved and available for sending with the request.
How to do this job? redirect after a successful cookie event.
function set_location_cookie() { if(isset($_POST['location'])) { // Set Cookie setcookie('location', $_POST['location'], time()+1209600); // Reload the current page so that the cookie is sent with the request header('Location: '.$_SERVER['REQUEST_URI']); } } add_action('init', 'set_location_cookie');
Can I also use flag images as submit buttons? Yes, use CSS to style your input buttons.
Add an identifier to each input: id="uk-button" and id="world-button"
CSS
#uk-button { background-image: url(uk-flag.png); background-size: 100%; background-repeat:no-repeat; } #world-button { background-image: url(world-flag.png); background-size: 100%; background-repeat:no-repeat; }