我使用WordPress主题报纸。现在日期显示为“2017年7月26日”,但我希望它显示为“4小时前”或“3天前”。环顾四周后,我发现有一个WordPress代码可以做到这一点。但是,我无法弄清楚如何用人类时间差异替换我网站的当前日期。有没有人有什么建议?如何将日期更改为前几天(人类时差)
的获取日期函数我的主题使用:
function get_date($show_stars_on_review = true) {
$visibility_class = '';
if (td_util::get_option('tds_m_show_date') == 'hide') {
$visibility_class = ' td-visibility-hidden';
}
$buffy = '';
if ($this->is_review and $show_stars_on_review === true) {
//if review show stars
$buffy .= '<div class="entry-review-stars">';
$buffy .= td_review::render_stars($this->td_review);
$buffy .= '</div>';
} else {
if (td_util::get_option('tds_m_show_date') != 'hide') {
$td_article_date_unix = get_the_time('U', $this->post->ID);
$buffy .= '<span class="td-post-date">';
$buffy .= '<time class="entry-date updated td-module-date' . $visibility_class . '" datetime="' . date(DATE_W3C, $td_article_date_unix) . '" >' . get_the_time(get_option('date_format'), $this->post->ID) . '</time>';
$buffy .= '</span>';
}
}
return $buffy;
}
当函数被调用:
<div class="item-details">
<?php echo $this->get_title();?>
<div class="td-module-meta-info">
<?php if (td_util::get_option('tds_category_module_mx1') == 'yes') { echo $this->get_category(); }?>
<span class="td-author-date">
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
</span>
</div>
<div class="td-excerpt">
<?php echo $this->get_excerpt();?>
</div>
</div>
人的时间差异代码:
<?php echo str_replace('mins', 'minutes', human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'); ?>
我在哪里元素试图更改日期
<?php
class td_module_2 extends td_module {
function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}
function render() {
ob_start();
?>
<div class="<?php echo $this->get_module_classes();?>">
<div class="td-module-image">
<?php echo $this->get_image('td_324x160');?>
<?php if (td_util::get_option('tds_category_module_2') == 'yes') { echo $this->get_category(); }?>
</div>
<?php echo $this->get_title();?>
<div class="td-module-meta-info">
<?php echo $this->get_author();?>
<?php echo wp_relative_date(get_the_time('U'));?>
</div>
<div class="td-excerpt">
<?php echo $this->get_excerpt();?>
</div>
<?php echo $this->get_quotes_on_blocks();?>
</div>
<?php return ob_get_clean();
}
}
感谢试图帮助。我得到了这个错误 - 解析错误:语法错误,意外'$ post_date_time'(T_VARIABLE),期待函数(T_FUNCTION)在这一行 - $ post_date_time = get_the_date()。 ''。 get_the_time(); //格式化为m/d/Y H:i:s – user7548188
确保将正确的格式添加到get_the_date和time中。 EG get_the_date('m/d/Y')等 –