Tutorial 3: How filter the content of wordpress for country

in #utopian-io7 years ago

Tutorial 3: How filter the content of wordpress for country

Today i want show you guys an advance tutorial for wordpress designers, the first time i was to do this was a headache for me, thats the reason

to share, avoid the suffering and contribute the community
Things we need:
• wordpress instalation
• install the plugin geoip_detection
• install the plugin XYZ php code
• FTP application if the wordpress instalation is in the web
• basic knowlege about php and wordpress

1.- When all this is completely installed the first the we have to do is créate a file with the name ip_detection.php (for the example) and put this

code inside:

// if the cookie is empty I detect the ip and assign. if(empty($_COOKIE["pais"])){ // we need install and activate the GeoIP Detection plugin $geoip = geoip_detect2_get_info_from_current_ip(); $country = $geoip->raw[ 'country' ][ 'iso_code' ]; //echo $country; // I assign global value if the detection of ip does not coincide with any of the countries will remain globalsetcookie("pais", "global",time() + 3600, '/', '.yourweb.com'); //////////////////// if ($country=='AR'){setcookie("pais","argentina",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="argentina"; } if ($country=='BO'){setcookie("pais","bolivia",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="bolivia";} if ($country=='CL'){setcookie("pais","chile",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="chile";} if ($country=='CO'){setcookie("pais","colombia",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="colombia";} if ($country=='CR'){setcookie("pais","costa-rica",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="costa-rica";} if ($country=='SV'){setcookie("pais","el-salvador",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="el-salvador";} if ($country=='ES'){setcookie("pais","espana",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="espana";} if ($country=='HN'){setcookie("pais","honduras",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="honduras";} if ($country=='GT'){setcookie("pais","guatemala",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="guatemala";} if ($country=='NCA'){setcookie("pais","nicaragua",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="nicaragua";} if ($country=='PY'){setcookie("pais","paraguay",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="paraguay";} if ($country=='PE'){setcookie("pais","peru",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="peru";} if ($country=='UY'){setcookie("pais","uruguay",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="uruguay";} if ($country=='VE'){setcookie("pais","venezuela",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="venezuela";} } else { // If the cookie is not empty, I do not do anything. if(empty($_GET["pais"])){ }else{ $country=$_GET["pais"]; if ($country=='GLOBAL'){setcookie("pais","global",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="global"; } if ($country=='AR'){setcookie("pais","argentina",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="argentina"; } if ($country=='BO'){setcookie("pais","bolivia",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="bolivia";} if ($country=='CL'){setcookie("pais","chile",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="chile";} if ($country=='CO'){setcookie("pais","colombia",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="colombia";} if ($country=='CR'){setcookie("pais","costa-rica",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="costa-rica";} if ($country=='SV'){setcookie("pais","el-salvador",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="el-salvador";} if ($country=='ES'){setcookie("pais","espana",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="espana";} if ($country=='HN'){setcookie("pais","honduras",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="honduras";} if ($country=='GT'){setcookie("pais","guatemala",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="guatemala";} if ($country=='NCA'){setcookie("pais","nicaragua",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="nicaragua";} if ($country=='PY'){setcookie("pais","paraguay",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="paraguay";} if ($country=='PE'){setcookie("pais","peru",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="peru";} if ($country=='UY'){setcookie("pais","uruguay",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="uruguay";} if ($country=='VE'){setcookie("pais","venezuela",time() + 3600, '/', '.yourweb.com');$_COOKIE["pais"]="venezuela";} } } if ($_COOKIE["pais"]=='global'){$mostrar="Global";} if ($_COOKIE["pais"]=='argentina'){$mostrar="Argentina";} if ($_COOKIE["pais"]=='bolivia'){$mostrar="Bolivia";} if ($_COOKIE["pais"]=='chile'){$mostrar="Chile";} if ($_COOKIE["pais"]=='colombia'){$mostrar="Colombia";} if ($_COOKIE["pais"]=='costa-rica'){$mostrar="Costa rica";} if ($_COOKIE["pais"]=='el-salvador'){$mostrar="El salvador";} if ($_COOKIE["pais"]=='espana'){$mostrar="España";} if ($_COOKIE["pais"]=='honduras'){$mostrar="Honduras";} if ($_COOKIE["pais"]=='guatemala'){$mostrar="Guatemala";} if ($_COOKIE["pais"]=='nicaragua'){$mostrar="Nicaragua";} if ($_COOKIE["pais"]=='panama'){$mostrar="Panama";} if ($_COOKIE["pais"]=='paraguay'){$mostrar="Paraguay";} if ($_COOKIE["pais"]=='peru'){$mostrar="Peru";} if ($_COOKIE["pais"]=='uruguay'){$mostrar="Uruguay";} if ($_COOKIE["pais"]=='venezuela'){$mostrar="Venezuela";} ?>

If the desire country is not in the list you can added, just need Reading the documentation of geoip Plugin -

https://es.wordpress.org/plugins/geoip-detect/ - o just ask me in the comments
This file you can save in the same folder of your current wordpress theme, then in the same folder we need to find the file with the code of the

header of your theme to insert this line:
include_once' ip_detection.php' ;
with this you can obtain the initial of the country from the people who visit your site, this result is based in the his ip address compared in the

database of Geo ip, after that we save the country in one cookie variable to use when is necesary, to avoid do the same check everytime the page is

reloaded we are using a conditional If at the start to verify the cookie variable

2.- Go to XYZ php code snippets inside your wordpress dashboard and create a new php snippet
Inside this snippet you can put your php code, you dont need use the tags
, the plugin does for you.


1.jpg
2.jpg

Now you can insert your content using the conditional IF to filter using the cookie variable created before,you can use this to show diferents

social network for the active country or contact forms. I show two examples:
EXAMPLE A

if ($_COOKIE["pais"]=="global"){ $facebook="https://www.facebook.com/global/?ref=br_rs"; $twitter="https://twitter.com/global"; } if ($_COOKIE["pais"]=="bolivia"){$facebook="https://www.facebook.com/boliviar "; $twitter="https://twitter.com/bolivia";} if ($_COOKIE["pais"]=="colombia"){$facebook="https://www.facebook.com/colombia /?ref=br_rs";$twitter="https://twitter.com/colombia";} if ($_COOKIE["pais"]=="chile"){$facebook="https://www.facebook.com/ chile /?ref=br_rs";$twitter="https://twitter.com/chile";} if ($_COOKIE["pais"]=="el-salvador"){$facebook="https://www.facebook.com/ el-salvador /?ref=br_rs";$twitter="https://twitter.com/el-salvador";} if ($_COOKIE["pais"]=="guatemala"){$facebook="https://www.facebook.com/guatemala /?ref=br_rs";$twitter="https://twitter.com/guatemala";} if ($_COOKIE["pais"]=="paraguay"){$facebook="https://www.facebook.com/paraguay /?fref=ts";$twitter="https://twitter.com/paraguay";} if ($_COOKIE["pais"]=="peru"){$facebook="https://www.facebook.com/peru /?fref=ts";$twitter="https://twitter.com/peru ";} if ($_COOKIE["pais"]=="uruguay"){$facebook="https://www.facebook.com/uruguay /?fref=ts";$twitter="https://twitter.com/uruguay";} if ($_COOKIE["pais"]=="venezuela"){$facebook="https://www.facebook.com/venezuela/?ref=br_rs";$twitter="https://twitter.com/venezuela";} echo $facebook; echo $twitter; EXAMPLE B (if you use contact form 7) if ($_COOKIE["pais"]=="global"){ $form='[contact-form-7 id="6" title="Contact Global"]'; } if ($_COOKIE["pais"]=="argentina"){ $form='[contact-form-7 id="23737" title="Contact ARGENTINA"]'; } if ($_COOKIE["pais"]=="bolivia"){ $form='[contact-form-7 id="23706" title="Contact Bolivia"]'; } if ($_COOKIE["pais"]=="colombia"){ $form='[contact-form-7 id="23707" title="Contact Colombia"]'; } if ($_COOKIE["pais"]=="chile"){ $form='[contact-form-7 id="23708" title="Contact CHILE"]'; } if ($_COOKIE["pais"]=="el-salvador"){ $form='[contact-form-7 id="23710" title="Contact El Salvador"]'; } if ($_COOKIE["pais"]=="guatemala"){ $form='[contact-form-7 id="23709" title="Contact Guatemala"]'; } if ($_COOKIE["pais"]=="paraguay"){ $form='[contact-form-7 id="23711" title="Contact PARAGUAY"]'; } if ($_COOKIE["pais"]=="peru"){ $form='[contact-form-7 id="23712" title="Contact PERU"]'; } if ($_COOKIE["pais"]=="uruguay"){ $form='[contact-form-7 id="23713" title="Contact URUGUAY"]'; } if ($_COOKIE["pais"]=="venezuela"){ $form='[contact-form-7 id="23714" title="ContactVENEZUELA"]'; } echo do_shortcode($form); Well this everything for now, i hope you liked and you can use, Questions and suggestions in the comments and. We see each other in the next tutorial. Regards Tutorial 1: direct access virus Tutorial 2: Sacrific graphics by speed @yjrvsoftware

Sort:  

Gracias por enseñarnos a usar el programa.... Al fin me lo enseñan jejejejejeje

Muy interesante tu post! <3

continues to provide quality post, very interesting