php - 从 2016 年 3 月 3 日开始每三个星期四回显

标签 php wordpress

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

从 2016 年 3 月 3 日开始,他们每个第 3 个星期四召开一次董事会 session

我正在尝试创建一个简码

我想回应下次 session 的时间。

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

// 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 中执行简单的任务。

最佳答案

此代码将使您获得当月的第三个星期四..

如果当前日期已经过了第 3 个星期四,那么它会显示下个月的第 3 个星期四。如果当前月份是 12 月并且已经过了第 3 个星期四,那么它会显示明年 1 月的第 3 个星期四

<?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));
}?>

This will show only one 3rd Thurs of either Current Month or Next Month depending on the current date.. If you want the 3rd Thurs of next 2-3 month then you can make some changes I guess now !!!

关于php - 从 2016 年 3 月 3 日开始每三个星期四回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35793878/

相关文章:

php - 为一天的开始和结束创建 DateTime 字符串

php - 根据select查询结果更新数据库记录

html - 如何使用自定义 wordpress 主题使 div 响应?

javascript - 在 JQuery 文件中获取 WordPress 帖子 ID

php - 在使用 PHPUnit 进行测试时使用实现 IteratorAggregate 接口(interface)的 Mock 类时如何防止重新声明错误?

php - 显示来自计数查询的个人数据(mySQL/php)

WordPress 自定义字段可从现有帖子中进行选择

php - 解析 WordPress 帖子内容

php - wordpress:发送电子邮件时将字段保存到数据库 - 错误 500

css - 可扩展的特色图片 - Wordpress