Нужно сделать вывод даты комментариев так:
"% часов/минут/секунд назад"
Подскажите, как реализовать.
Вот функции:
function get_comment_date( $d = '', $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( '' == $d )
$date = mysql2date(get_option('date_format'), $comment->comment_date);
else
$date = mysql2date($d, $comment->comment_date);
/**
* Filter the returned comment date.
*
* @since 1.5.0
*
* @param string|int $date Formatted date string or Unix timestamp.
* @param string $d The format of the date.
* @param WP_Comment $comment The comment object.
*/
return apply_filters( 'get_comment_date', $date, $d, $comment );
}
function get_comment_time($d = '', $gmt = false, $translate = true){
$comment = get_comment();
$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
if ('' == $d)
$date = mysql2date(get_option('time_format'), $comment_date, $translate);
else
$date = mysql2date($d, $comment_date, $translate);
/**
* Filter the returned comment time.
*
* @since 1.5.0
*
* @param string|int $date The comment time, formatted as a date string or Unix timestamp.
* @param string $d Date format.
* @param bool $gmt Whether the GMT date is in use.
* @param bool $translate Whether the time is translated.
* @param WP_Comment $comment The comment object.
*/
return apply_filters('get_comment_time', $date, $d, $gmt, $translate, $comment);
}
Сейчас выводится так:
function _ago($tm, $rcs = 0)
{
$cur_tm = time();
$dif = $cur_tm - $tm;
$pds = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); $v--) ;
if ($v < 0) $v = 0;
$_tm = $cur_tm - ($dif % $lngh[$v]);
$no = floor($no);
if ($no <> 1) $pds[$v] .= 's';
$x = sprintf("%d %s ", $no, $pds[$v]);
if (($rcs == 1) && ($v >= 1) && (($cur_tm - $_tm) > 0)) $x .= time_ago($_tm);
return $x;
}
UPD 1 : Carbon
Установить Carbon через composer
:
{
"require": {
"nesbot/carbon": "~1.18"
}
}
В РНР:
<?php
use Carbon\Carbon;
echo Carbon::now()->diffForHumans($article->time);
Оборудование для ресторана: новинки профессиональной кухонной техники
Частный дом престарелых в Киеве: комфорт, забота и профессиональный уход
Залил сайт на хостинг, очень долго грузятся страницы, иногда вылетает ошибка 500Вот ссылка на сайт: ссылка
Пытаюсь задать сессии определённое значение, но когда перехожу по страницам сайта значение опять сбрасывается на дефолтное, помогите, пожалуйста...
Для пробы создал на denwer мини сайт для пробы , вывел статьи из базы и так же создал слайдер на owl-carouselЦиклом выводил url адреса изображений и через...
Пытаюсь в базу занести дату с интервалом в 1 день,использую следующий запрос