解决DUX主题侧边栏最近评论评论时间不准的问题

释放双眼,带上耳机,听听看~!

[hermit autoplay=”false” mode=”circulation” preload=”auto”]netease_songlist#:1346053083[/hermit]

其实博主老早就发现这个问题了,也百度了方法,几乎都是让你更改程序或php.ini的时区,但原因并不是这样,下面我们来慢慢分析~

WordPress 的默认时区是 UTC 格林威治时间,我看我后台常规设置中选的就是上海时区,但是就算是将 WordPress 时区调整为上海或 UTC+8 后,前台评论时间显示均还是 UTC 时间,与北京时间仍有 8 小时的时差,而后台评论的时间是正确的,也就是说后台的时区设置对前台评论不起作用。

后来在我翻看数据库时发现了神奇的玩意

解决DUX主题侧边栏最近评论评论时间不准的问题

这尼玛不是刚好差八小时吗!!!

解决DUX主题侧边栏最近评论评论时间不准的问题

[qgg_pink]原来dux默认调用的时UTC的时区(如果没错的话),所以这里直接改成以PRC时区的时间就OK了。[/qgg_pink]

[qgg_green]修改地址为:wp-content/themes/dux/widgets 下面直接贴出代码。[/qgg_green]

$sql = "SELECT DISTINCT ID, post_title, post_password, user_id, comment_ID, comment_post_ID, comment_author, comment_date, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,100) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_post_ID!='".$outpost."' AND user_id!='".$outer."' AND comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $limit";
$comments = $wpdb->get_results($sql);

$output = '';
foreach ( $comments as $comment ) {
$output .= '<li><a href="'.get_comment_link($comment->comment_ID).'" title="'.$comment->post_title.'上的评论">'._get_the_avatar($user_id=$comment->user_id, $user_email=$comment->comment_author_email).' <strong>'.$comment->comment_author.'</strong> '._get_time_ago( $comment->comment_date ).'说:<br>'.str_replace(' data-original=', ' src=', convert_smilies(strip_tags($comment->com_excerpt))).'</a></li>';
}

OK 完事收工解决DUX主题侧边栏最近评论评论时间不准的问题

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA赞赏
共{{data.count}}人
人已赞赏
技术教程

MIUI10 修改破解系统VIP下载加速

2019-2-2 15:22:05

技术教程

宝塔nginx 1.15.9编译云锁安全模块/一键脚本

2019-3-27 22:14:23

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索