-1

I want a system to make "Country Ways Content Show" on the homepage. I posting separating country in every country in the different category. Think you are from USA, when you visit then only under America category's post will show you, not others country's content. Like this way if a Portuguese people visit then he will see content from Portugal category, he never see USA content but can browse manually from category list. Thanks

  • so what is actually the question? – Mark Kaplun Jan 22 '18 at 8:30
  • I want to know how can I make this system. I want different content for each different country. Thanks – MOHSINWORLD Jan 22 '18 at 8:32
  • "Someone write code for me for free" is not a question. You should try to make it yourself and ask about your own code and design. – Mark Kaplun Jan 22 '18 at 11:04
2

This is actually quite easy to do: You will need to install a geolacation plugin that provides methods/functions to identify visitor country. N.B. A plugin only providing shortcodes will not work.

The only complicating factor is countries can be named in a variety of ways so 2 character ISO Country Codes have to be used for reliable visitor identifcation.

You could rename all your categories by adding an ISO code sufffix e.g. "Canada (CA)"; but association with visitors will be complicated and involve more code. So the example below assumes you will add either a 2nd category or a tag with the relevant uppercase ISO code e.g. "CA" to each post.

(tested and works for me)

  1. Add a 2nd category (or tag) to each of your posts named as per 2 char ISO country code (ensure uppercase).

  2. Install and activate the Category Country Aware plugin (as the author I'm familiar with it and so its the one I used it in the code below).

  3. use an editor to create this plugin file (if using tags remove the 2 category lines, and uncomment the tag line as explained in comments)

    <?php
    /*
    Plugin Name: Category for Visitor
    Description: only show posts for visitor's country on home page
    */
    function my_visitors_category( $query ) {
      if (! class_exists('CCAgeoip')) return;
      $cat_id = get_cat_ID( CCAgeoip::get_visitor_country_code() ); // remove this line if using tag instead of 2nd cat
      if ( $query->is_home() && $query->is_main_query() ) {
             $query->set( 'cat', $cat_id); // remove this line if using tags
             // $query->set( 'tag', CCAgeoip::get_visitor_country_code() );  // uncomment this line if using tags for country ISO
      }
    }
    add_action( 'pre_get_posts', 'my_visitors_category' );
    ?>
    
  4. save as "visitor-category.php"; then Zip the file

  5. Upload the zipped file via WP Dashboard->plugins->ad new->upload and activate

  • I think this is a complicated way explained me. I would need something that works straight. Add a shortcode in homepage [Like this [plugin-name countrycontent] then this shortcode will show particular category based content targeted for the country using 2 char ISO country code. To identify the category there can be a tag field in the category, so the plugin can identify through 2 char ISO country code the category is listed for which country. – MOHSINWORLD Jan 23 '18 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.