the_date()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
the_date( string $format = '', string $before = '', string $after = '', bool $display = true ): string|null
Описание
Дата выводится только в том случае, если дата текущей записи отличается от предыдущей выведенной.
То есть за каждый день из показанных в цикле записей выводится только одна дата, даже если функция вызывается несколько раз для каждой записи.
HTML-вывод можно изменить фильтром 'the_date'.
Строку с датой можно изменить фильтром 'get_the_date'.
Оригинал (английский)
Will only output the date if the current post’s date is different from the previous one output.
i.e. Only one date listing will show per day worth of posts shown in the loop, even if the function is called several times for each post.
HTML output can be filtered with ‘the_date’.
Date string output can be filtered with ‘get_the_date’.
Параметры
$format
string
необязательный
= ''
$before
string
необязательный
= ''
$after
string
необязательный
= ''
$display
bool
необязательный
= true
Возвращаемое значение
string|null
Исходный код
wp-includes/general-template.php:2686
function the_date( $format = '', $before = '', $after = '', $display = true ) {
global $currentday, $previousday;
$the_date = '';
if ( is_new_day() ) {
$the_date = $before . get_the_date( $format ) . $after;
$previousday = $currentday;
}
/**
* Filters the date of the post, for display.
*
* @since 0.71
*
* @param string $the_date The formatted date string.
* @param string $format PHP date format.
* @param string $before HTML output before the date.
* @param string $after HTML output after the date.
*/
$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );
if ( $display ) {
echo $the_date;
} else {
return $the_date;
}
}
История изменений
| Версия | Описание |
|---|---|
| 0.71 | Introduced. |

