【问题标题】:Show Last Updated Time instead of Published Time显示上次更新时间而不是发布时间
【发布时间】:2018-10-05 22:34:09
【问题描述】:

我对 PHP 很陌生。我想显示上次更新日期而不是发布时间。有人能帮我吗?非常感谢。

    if ( ! function_exists( 'minimalistblogger_posted_on' ) ) :
    function minimalistblogger_posted_on() {
        $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
            $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
        }

        $time_string = sprintf( $time_string,
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() ),
            esc_attr( get_the_modified_date( 'c' ) ),
            esc_html( get_the_modified_date() )
        );

        $posted_on = sprintf(
            esc_html_x( 'Posted on %s', 'post date', 'minimalistblogger' ),
            '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
        );

        $byline = sprintf(
            esc_html_x( 'by %s', 'post author', 'minimalistblogger' ),
            '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
        );

        echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.

    }
endif;

【问题讨论】:

  • 你这里用什么框架?
  • $timestring 可能会显示更新的日期,但在设置后从未使用过。
  • 它在 Wordpress 上。但在帖子上,它只显示“发布于……发布日期……”

标签: php wordpress date datetime


【解决方案1】:

啊!我找到了!

只需使用

get_the_modified_time('F d, Y');

$modifiedtime = get_the_modified_time('F d, Y'); $posted_on = sprintf( esc_html_x( '最后修改于 %s', '发布日期', 'minimalistblogger' ), '' . $修改时间。 '');

谢谢你:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多