Php 添加一天以获取Wordpress中的日期
在WPTouch主题中,发布日期显示在一个大气泡中。然而,帖子是在前一天晚上添加的,所以这一天已经落后一天了。为了解决这个问题,我更改了这一行:Php 添加一天以获取Wordpress中的日期,php,mysql,wordpress,Php,Mysql,Wordpress,在WPTouch主题中,发布日期显示在一个大气泡中。然而,帖子是在前一天晚上添加的,所以这一天已经落后一天了。为了解决这个问题,我更改了这一行: <?php wptouch_the_time( 'j' ); ?> 为此: <?php $date = DateTime::createFromFormat('m-d-Y', mysql2date('m-d-Y', $post->post_date)); $date-&g
<?php wptouch_the_time( 'j' ); ?>
为此:
<?php
$date = DateTime::createFromFormat('m-d-Y', mysql2date('m-d-Y', $post->post_date));
$date->modify('+1 day');
echo $date->format('j');
?>
这是可行的,但是非常丑陋。我认为应该有一种更好的方法从mysql日期获取php日期时间。您可以使用此方法在使用函数get_the_the_the_the_time最有可能用于获取日期的函数将日期赋予主题之前修改日期:
add_filter( 'get_the_date', 'modify_get_the_date', 10, 3 );
function modify_get_the_date( $value, $format, $post ) {
$date = new DateTime( $post->post_date );
$date->modify( "+1 day" );
if ( $format == "" )
$format = get_option( "date_format" );
return( $date->format( $format ) );
}
也就是说,与其修改从数据库读取的日期,不如在写入时存储发布日期。你可以将文章安排在第二天,而不是直接发布。你可以这样做
<?php
$date=date_create();
date_modify($date,"+1 month");
echo date_format($date,"Y-m-d");
?>
我经常这样做的方法是使用
我宁愿在WordPress中使用正确的日期,将文章安排在第二天发布,而不是直接发布。好吧,不太正确的版本是使用日期和strotime:echo date'j',strotime$post->post_date+1天';超过一天的时间来添加它应该是什么样子