刚在winysky博客看到一篇教程,是给WordPress博客添加提示访客最近评论次数效果的,记得以前也看到部分博客有这个功能,但忘记是哪个博客了。博客吧觉得给博客添加这个效果很好,不但能提示访客留言评论,而且在一定程度上也能提高访客的留言积极性,博客吧参照原文说明下添加方法。
最近评论次数实现方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php //copy下面的代码到主题function.php里调用 /** * welcome message * @param unknown_type $email * @return void|string */ function WelcomeCommentAuthorBack($email = ''){ if(empty($email)){ return; } global $wpdb; $past_30days = gmdate('Y-m-d H:i:s',((time()-(24*60*60*30))+(get_option('gmt_offset')*3600))); $sql = "SELECT count(comment_author_email) AS times FROM $wpdb->comments WHERE comment_approved = '1' AND comment_author_email = '$email' AND comment_date >= '$past_30days'"; $times = $wpdb->get_results($sql); $times = ($times[0]->times) ? $times[0]->times : 0; $message = $times ? sprintf(__('过去30天内您评论了<strong>%1$s</strong>次,感谢关注~' ), $times) : '您很久都没有留言了,这次想说点什么吗?'; return $message; } |
1 | <?php echo WelcomeCommentAuthorBack($comment_author_email); ?> |
教程相关代码来自
http://winysky.com/wordpress-shows-the-number-of-recent-comments