workpress 时间显示问题修改

时间:2020-07-21 15:17:46   收藏:0   阅读:50
<?php
$postThumbnail = get_the_post_thumbnail_url($post->ID, ‘hero-large‘);
?>

<a href="<?php echo get_permalink($post); ?>" class="c-news-card">
    <div class="c-background-image" style="background-image: url(<?php echo $postThumbnail; ?>)"></div>
    <div class="c-news-card__content">

        <div class="c-news-card__published">
            <?php
            if(ICL_LANGUAGE_CODE === ‘en‘) {
                // 修改前:时间取值不对,获取的是 page 发布时间,应该取文章发布时间             
                // printf( _x( ‘%s ago‘, ‘%s = human-readable time difference‘, ‘swiss‘ ), human_time_diff( get_the_time( ‘U‘ ), current_time( ‘timestamp‘ ) ) );
                printf( _x( ‘%s ago‘, ‘%s = human-readable time difference‘, ‘swiss‘ ), human_time_diff( get_the_time( ‘U‘, $post->ID ), current_time( ‘timestamp‘ ) ) );
            } else {
                echo get_the_date(get_option(‘date_format‘), $post->ID);
            }
            ?>
        </div>
        <h3 class="c-news-card__title"><?php echo $post->post_title; ?></h3>
        <div class="c-news-card__excerpt"><?php echo $post->post_excerpt; ?></div>
    </div>
</a>
$ /etc/init.d/php-fpm restart

参考网址:
https://www.66004.cn/help/view244.html
https://developer.wordpress.org/reference/functions/get_the_time/

原文:https://www.cnblogs.com/doraman/p/13354520.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!