仅在与Wordpress中的已发布日期不同时显示更新日期

时间:2017-01-28 23:21:50

标签: wordpress wordpress-theming

尝试显示已发布日期和更新日期(如果它与发布日期不同),我在wordpress模板中尝试了此代码:

<p class="card-text">Published <?php the_date();?>.&nbsp;
<?php  
    if ( the_date( 'U' ) !== the_modified_date( 'U' ) ) {
        echo "Updated " . the_modified_date('F j, Y');
    }
    ?>

然而,我做网获得任何输出。可能很简单,但我只能输出很长的数字。

1 个答案:

答案 0 :(得分:1)

您应该使用get_the_dateget_the_modified_date,因为它们会返回值而不会将其打印出来。

if ( get_the_date( 'U' ) !== get_the_modified_date( 'U' ) ) {
    echo "Updated " . get_the_modified_date('F j, Y');
}