- CMS系统版本:wordpress 4.8.3
- 使用主题:swiss 2.6.0
- 代码部署路径:/data/******2017/dist/wp-content/themes/swiss/templates/components
- 数据库信息:******com2017
- 主题模板组件:c-news-card.php
- 源代码:
<?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>
- 重启 php 服务
$ /etc/init.d/php-fpm restart
参考网址:
https://www.66004.cn/help/view244.html
https://developer.wordpress.org/reference/functions/get_the_time/