繁体   English   中英

PHP如果日期是x并且时间大于x pm,则显示A;否则,如果显示B

[英]PHP If date is x and time is greater than x pm show A else if show B

我正在尝试让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月。 (表示每月5pm的第一天到每月4:59 pm的第二天,显示其他..)

第一点是优先事项。 请尽我所能,请帮助我。 但是我不知道如何解决时间问题。

这就是我发现的。 我仍然不确定100%,但是我认为这可以

if((date('j') == 25 && date('G') >= 17) || (date('j') == 26 && date('G') < 17)){ 
$adventdatepost = get_post('insert id for day 25);
}
else 
{
$adventdatepost = get_post('insert id for the post I want till 30 or 31st');
}

这告诉它是一个月的一天是1且时间大于5pm,还是日期是2且时间小于5pm ...显示第1天的信息

依此类推,直到25天。 然后在第25天之后,它可以将特定的帖子发布到该月的下一个1天。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM