可能大部Wordpress用户为了美化主题外观,都会使用WP-RecentComments插件增强最近留言显示功能
可能大部WordPress用户为了美化主题外观,都会使用WP-RecentComments插件增强最近留言显示功能
该插件最大的特色就是可以显示留言Gravatar头像,但还是那句话:越少的使用插件,却能让使用者完全体验到主题的各项功能,才是真正好的主题!一段函数代码就能实现的功能,何必调用烦杂的插件。
下面的两段函数代码就可以完全替代留言增强插件。
这两段函数代码,分别具有显示日志作者的留言和不显示作者留言功能,为 什么要去掉作者的留言呢,道理很简单,一般留言都显示在侧边,如果设置显示10条留言,正好有10位浏览者留言,而作者可能在同一时间内分别进行回复,结 果就是侧边显示的留言全部是作者自己的,不利于站长及时查看是否有新留言并回复。
代码一 :这段代码显示日志作者及浏览者的留言
<?php
global$wpdb;
$sql = \"SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,14) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = \'1\' AND comment_type = \'\' AND post_password = \'\' AND user_id=\'0\' ORDER BY comment_date_gmt DESC LIMIT 10\";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {$output .= \"n<li>\".get_avatar(get_comment_author_email(\'comment_author_email\'), 32).strip_tags($comment->comment_author).\":<br />\" . \" <a href=\"\" . get_permalink($comment->ID) .\"#comment-\" . $comment->comment_ID . \"\" title=\"on \" .$comment->post_title . \"\">\" . strip_tags($comment->com_excerpt).\"</a></li>\";}
$output .= $post_HTML;
echo $output;?>代码二: 这段代码不显示日志作者留言,只显示浏览者的留言
<?php
global $wpdb;
$sql = \"SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url,comment_author_email, SUBSTRING(comment_content,1,14) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = \'1\' AND comment_type = \'\' AND post_password = \'\' AND user_id=\'0\' ORDER BY comment_date_gmt DESC LIMIT 10\";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {$output .= \"n<li>\".get_avatar(get_comment_author_email(\'comment_author_email\'), 32).strip_tags($comment->comment_author).\":<br />\" . \" <a href=\"\" . get_permalink($comment->ID) .\"#comment-\" . $comment->comment_ID . \"\" title=\"on \" .$comment->post_title . \"\">\" . strip_tags($comment->com_excerpt).\"</a></li>\";}
$output .= $post_HTML;
echo $output;?>本站除原创内容,其余内容均收集自互联网,仅限用于学习和研究目的,本站不对其内容的合法性、可用性承担任何责任。本站禁止以任何形式发布或转载任何违法相关信息,若您发现请立即向站长举报;用户投稿一切资源内容不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
如有版权内容,其版权均归原作者所有,本站虽力求保存原有版权信息,但因众多资源经多次转载,已无法确定其真实来源,故敬请原作者谅解!为尊重作者劳动成果,请购买正版支持作者,谢谢!若您对「HULIKU.COM」所载资源作品版权归属存有异议,请发送邮箱:ihuliku@qq.com 进行处理。
本站资源文件大多存储至云盘,如您发现图片或链接失效,请联系站长或作者,我们将及时进行更新。资源都是经过站长或作者收集测试优化后进行发布分享。如若转载请在贵站文内以超链形式注明狐狸库文章出处,谢谢合作!













![WordPress子比主题美化教程合集[2023/04/17]-狐狸库](https://huliku.com/pic/2023032607024935.png)
![狐狸库自定义子比主题底部footer页脚美化(自适应)[06.26]更新-狐狸库](https://huliku.com/pic/2023062610013835.png)






















请登录后查看评论内容