【发布时间】:2016-11-16 01:40:13
【问题描述】:
我试图告诉 wordpress 功能根据一些复杂的因素(条件)显示发布日期
我必须展示帖子的出现风格。从 12 月 1 日开始,每天都会在网站的这个位置放置一个新帖子。但问题是加拿大(全部)、加拿大(BC)和美国的职位不同。所以这就是我本质上想要它做的事情
时区:埃德蒙顿
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)
我已经能够得到我想要的大部分内容,但我无法添加时间因素,因为我对 php 的了解不够 现在我的代码仅在日期设置和基于 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 .......
总结问题是: 1.而不是仅仅在日期上,我需要它根据日期和时间显示 2. 如果这不是太复杂,我希望实际上能够编辑它以在每个月的几天而不是仅仅在 12 月工作。 (意思是每月的第一天下午 5 点到每月的第二天下午 4:59 显示这个 else ..)
第 1 点优先。请帮助我,因为我已经尽力做到这一点。但我不知道如何解决时间问题。
【问题讨论】:
-
不要使用字符串,你只是让比较日期和时间变得更加困难,要么使用 unix 时间戳,要么改用
DateTime类,然后你在两者之间进行检查 -
@Ghost 是的,但这将指定仅在 12 月 - 如果我希望每个月都基于当月的某天以及下午 5:00 到第二天下午 4:59 之间的时间,该怎么办?跨度>
-
不管是几月,
DateTime肯定能满足这个条件
标签: php wordpress date if-statement time