0

我正在使用启动博客主题。我想使用上次更新日期而不是发布日期。经过一番搜索,我知道我需要用 the_modified_date() 替换函数 get_the_date() 或 the_date()。但是在代码中我无法理解 $date 变量的定义以及如何添加上述函数。

<?php
$author_display = get_theme_mod( 'post_byline_author' );
$date_display   = get_theme_mod( 'post_byline_date' );

if ( $author_display == 'no' && $date_display == 'no' ) {
return;
}

$author = get_the_author();
// add compatibility when used in header before loop
if ( empty( $author ) ) {
global $post;
$author = get_the_author_meta( 'display_name', $post->post_author );
}
$date   = date_i18n( get_option( 'date_format' ), strtotime( get_the_date( 
'r' ) ) );

echo '<div class="post-byline">';
if ( $author_display == 'no' ) {
// translators: %s = the date the post was published
printf( esc_html_x( 'Published %s', 'This blog post was published on some 
date', 'startup-blog' ), esc_html( $date ) );
} elseif ( $date_display == 'no' ) {
// translators: %s = the author who published the post
printf( esc_html_x( 'Published by %s', 'This blog post was published by some 
author', 'startup-blog' ), esc_html( $author ) );
} else {
// translators: %1$s = the date the post was published. %2$s = the author 
who published it
printf( esc_html_x( 'Published %1$s by %2$s', 'This blog post was published 
on some date by some author', 'startup-blog' ), esc_html( $date ), esc_html( 
$author ) );
}
echo '</div>';
4

1 回答 1

1

如果要保持与上一个日期函数检索到的格式相同,请替换:

$date = date_i18n( get_option( 'date_format' ), strtotime( get_the_date( 'r' ) ) );

get_the_modified_date()

$date = date_i18n( get_option( 'date_format' ), strtotime( get_the_modified_date( 'r' ) ) );
于 2017-10-29T20:08:13.367 回答