【问题标题】:Wordpress shortcode to display post date +1 dayWordpress 短代码显示发布日期 +1 天
【发布时间】:2013-12-12 02:50:05
【问题描述】:

我正在尝试创建一个显示发布日期 +1 天的简码。示例:如果帖子是在 3 日发布的,我想要一个显示 4 日的简码。我尝试了以下方法,但没有得到我想要的结果。

// [nextday]  
function displaydate_next(){  
    return the_time('jS', strtotime('+1 day')); 
}  
add_shortcode('nextday', 'displaydate_next'); 
// end nextday date

【问题讨论】:

  • 它会给你带来什么结果?编辑:您必须将帖子的日期作为第二个参数传递给strtotime(),否则您将始终获得明天的日期

标签: php wordpress function date


【解决方案1】:

我认为您还需要获取月份和年份,以便计算第二天。以下是您需要的:

// [nextday]  
function displaydate_next(){  

$time = get_the_time('jS F, Y');
$date = strtotime(date("jS F, Y", strtotime($time)) . " +1 day");
return date('jS', $date); 

}  
add_shortcode('nextday', 'displaydate_next'); 
// end nextday date

【讨论】:

  • 谢谢!完美运行!
【解决方案2】:

您可以为此目的使用WP Date and Time Shortcode。只需将days="+1" 添加为属性即可。

例如:[wp-dt item="custom" format="jS" days="+1"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多