你需要get_the_time
, 不the_time
获取日期(后者返回值)。你还需要重新评估你是如何计算结束日期的——你不能只是“加上”天数。如果活动长度为3,但开始日期为31,该怎么办?
if ( $event_length ) {
// Get the unix timestamp of the post
$post_time = get_the_time( \'U\' );
// Increase the timestamp by the event length
$end_time = $post_time + $event_length * DAY_IN_SECONDS;
// Conditional date format depending on if the event ends in the same month
if ( date( \'m\', $post_time ) !== date( \'m\', $end_time ) )
echo date_i18n( \' - M j\', $end_time );
else
echo date_i18n( \' - j\', $end_time );
}