从2016年3月3日开始每隔三个星期四回音

时间:2016-03-04 10:38:32

标签: php wordpress

我正在使用wordpress为公司开发网站

他们从2016年3月3日起每隔3个星期四召开一次董事会会议

我正在尝试创建短代码

我希望在下次会议开始时回应。

这是我到目前为止所得到的,但这不正确。

// ECHO next board_meeting - Use [next_board_meeting]
add_shortcode( 'next_board_meeting', 'next_board_meeting_shortcode' );
function next_board_meeting_shortcode( $str ) {

echo date_i18n('l j F', strtotime('next thursday +2 week'));

}

我一直在网上搜索这样的内容,但我在这里,请求你的帮助。

有一种简单的方法可以做到这一点,还是我需要创建一个复杂的PHP脚本?

请记住,我刚学会了如何在php中完成简单的任务。

2 个答案:

答案 0 :(得分:7)

此代码将为您提供当月的第三个星期四..

如果当前日期已经过了第四个周四那么它将显示下个月的第四个周四..如果当前月份是12月并且已经过了第三个周四那么它将在明年的第四个周四显示1月

<?php
$current_date = strtotime(date("d.m.Y"));

//$final = date("Y-m-d", strtotime("+1 month", $time));

$FullMonth = date('F',$current_date);
$FullYear = date('Y',$current_date);
$Third_Thus = date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
$ThirdThus_tmstamp = strtotime($Third_Thus);
if($current_date <= $ThirdThus_tmstamp){
    echo date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
}
else{
    if($FullMonth != 'December'){
        $FullMonth = date('F',strtotime("+1 month", $current_date));
        $FullYear = date('Y',$current_date);
    } else{
        $Next_Year = strtotime("+1 year", $current_date);
        $FullYear = date('Y',$Next_Year);
        $FullMonth = date('F',strtotime("+1 month", $Next_Year));
    }
    echo date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
}?>
  

这将只显示当前月或下一个的第三个周四   一个月取决于当前日期..如果你想要第三个星期四   接下来的2-3个月,你可以做一些我现在想的改变!!!

答案 1 :(得分:0)

应该使用这个简单的短代码:

add_shortcode( 'next_board_meeting', 'next_board_meeting_shortcode' );

function next_board_meeting_shortcode( $str ) {

  if(strtotime("3 thursday", strtotime(date('Y-m-01 00:00:00'))) > time())
    echo date('Y-m-d', strtotime("3 thursday", strtotime(date('Y-m-01 00:00:00'))));
  else
    echo date('Y-m-d', strtotime("3 thursday", strtotime("next month", strtotime(date('Y-m-01 00:00:00')))));

}

演示:https://eval.in/530446

相关问题