私はWordPressテーマの新聞を使用しています。今は「2017年7月26日」のように表示されていますが、「4時間前」または「3日前」と表示されたいです。周りを見回した後、私はこれを行うWordPressのコードがあることを発見しました。しかし、私は自分のサイトの現在の日付を人間の時間差分と置き換える方法を理解できません。誰にも何か提案はありますか?日付を日に変更する方法(人間の時間差)
のget日付関数は、私のテーマは使用しています:
関数が呼び出され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と時刻に正しいフォーマットを必ず追加してください。 EG get_the_date( 'm/d/Y')など –