I am trying to tell a wordpress feature to display a post date based on some complicated factors (conditions)
I have to show an advent style of posts. Everyday starting Dec 1, a new post will be placed at this position of the site. But the catch is the posts are different for Canada (all), Canada (BC) and USA. So here is what I essentially want it to do
Timezone : Edmonton
If date is from dec 1 5:00pm to dec 2 4:59pm {
if the user is in BC
{show postid 1
}else if the user is in USA
{show postid 2
}else{
show postid 3
}
}else
if date is from dec 2 5:00pm to dec 3 4:59pm{
if the user is in BC
{show postid 4
}else if the user is in USA
{show postid 5
}else{
show postid 6
}
}else.....
so on for 25 days (till December 25th)
I have been able to get most of what I want but I was not able to add the time factor since I do not know enough in php right now my code only displays if the date is as set & based on the ip.
function showheroslider(){
date_default_timezone_set("America/Edmonton");
if (date('F, j, Y') == 'December, 1, 2016' ){
$userInfo = geoip_detect2_get_info_from_current_ip();
if ($userInfo->mostSpecificSubdivision->name == 'British Columbia'){
$adventdatepost = get_post(1123);
} else if ($userInfo->country->name == 'United States'){
$adventdatepost = get_post(1123);
} else {
$adventdatepost = get_post(1123);
}
} else
if (date('F, j, Y') == 'December, 2, 2016' ){
$userInfo = geoip_detect2_get_info_from_current_ip();
if ($userInfo->mostSpecificSubdivision->name == 'British Columbia'){
$adventdatepost = get_post(1097);
} else if ($userInfo->country->name == 'United States'){
$adventdatepost = get_post(1097);
} else {
$adventdatepost = get_post(1097);
}
} else
if (date('F, j, Y') == 'December, 3, 2016' ){
$userInfo = geoip_detect2_get_info_from_current_ip();
if ($userInfo->mostSpecificSubdivision->name == 'British Columbia'){
$adventdatepost = get_post(1206);
} else if ($userInfo->country->name == 'United States'){
$adventdatepost = get_post(1204);
} else {
$adventdatepost = get_post(1206);
}else .......
To summarize the issue is : 1. Instead of Just on the date, I need it to display based on date and time 2. If this is not too complicated I want to actually be able to edit this to work on days of every month instead of just for December. (Meaning 1st day of the month 5pm to 2nd day of the month 4:59pm show this else ..)
Point 1 is of priority. Please help me as I have tried my best to come this far. But I do not know how to tackle the time issue.
Aucun commentaire:
Enregistrer un commentaire