在使用the_modified_date()函数时需要帮助

时间:2017-10-29 20:02:12

标签: modified-date

我正在使用启动博客主题。而不是发布日期我想使用上次更新日期的帖子。经过一些搜索,我发现我需要用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>';

1 个答案:

答案 0 :(得分: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' ) ) );
相关问题