• I’m looking for a plugin that allows for separate nav structure per the country.

    For example in the US I can show abc products, but in mexico I can only show xyz products, yet for both countries everything else site wide is the same.

    Has anyone ran across a plugin that does this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi Tony,

    In order to accomplish this, I would use the following 2 components:
    1. A plugin that detects the user’s country. The only one I found is a premium one.
    2. Individual custom Nav Menus for each country. You would need to register as many nav menus as variables needed, crate them in WP admin panel (Appearance -> Menus), and call them dynamically from header.php based on the plugin’s test. For more information about WP menus, you should check out the following Codex articles:
    wp_register_menu
    wp_nav_menu
    Le me know if you need additional help.

    Good luck.

    For the first step, I also found this online tool called Geo/IO, which is free for up to 1,000 requests per day. I don’t know exactly how it works because I never tried it, but it seems like it is worth taking a look.

    Thread Starter Tony Bianco

    (@tbianco)

    That is extremely helpful Marventus!

    How would I go about including a set of menus? would I do this with PHP code within the template? or is there a plugin where I can configure which nav shows up.

    Basically that’s really what needs to happen here is to have a navigation menu that shows by which country code is required.

    for our website we have multiple countries opened up and a blog per the country. Would you suggest setting up a separate blog install per the country?

    I’m glad you found that useful.
    For this to work, you would first need to add as many menus as you need in your theme’s functions.php file. The wp_register_menus article I shared above covers this part. Make sure to backup the file first and to check whether your theme doesn’t already support menus before you make any changes to it.
    Then, as you well put it, you would have to include the new menus by editing your theme’s header.php file and inserting a conditional php statement so that only the country-relevant menu is displayed. If you use the premium plugin above, your code would look smth like this:

    <?php
    // Checks if plugin function exists.
    if (function_exists('isCountryInFilter')) {
    // If it does, checks if visitor's location is the US.
       if( isCountryInFilter(array("us")) ) {
    // If it is, displays menu for US.
          wp_nav_menu( array('menu' => 'US Menu') );
       }
    // If location is not the US, checks if visitor's location is Mexico.
       elseif( isCountryInFilter(array("mx")) ) {
    // If it is, displays menu for Mexico.
          wp_nav_menu( array('menu' => 'Mexico Menu') );
    // If location is either US or Mexico,
       } else {
    // Displays a default menu
          wp_nav_menu( array('menu' => 'Default Menu') );
       }
    }
    ?>

    If you only want to have US and Mexico menus and not fallback default menu, simply delete this line:

    wp_nav_menu( array('menu' => 'Default Menu') );

    Lines that start with // are for explanation purposes only and don’t have any effect on the actual code.

    Hi Tony,

    Were you able to figure this out?
    Don’t hesistate to let me know if you need more help.

    Cheers!

    Thread Starter Tony Bianco

    (@tbianco)

    This looks like all that I need for now. I haven’t gotten around to this part of the project yet. I’m familiar with PHP programming just not all the ins and outs of the WordPress framework. Still learning my way around all the files.

    I’ll let you know if I run into any problems.

    Marventus

    (@marventus)

    Hi,

    Were you able to figure this out? If so, could you please mark this topic as resolved?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Seperate Nav Structure per Language?’ is closed to new replies.