WordPess调用最新评论插件
发布时间:November 9, 2007 分类:WordPress
想放个最新评论在首页显示,结果找了半天也没找到wordpress的调用最新评论的插件,很是郁闷~~~
算了,自己写个吧,这个是wordpress的调用最新评论的插件,大家可以看看~~
使用WordPess调用最新评论插件方法如下:
| <div class="mod"><h3>最新评论</h3><br /><ul> |
| < ?php get_recent_comments(); ?> |
| </ul></div> |
在使用< ?php get_recent_comments(); ?>的页面(比如我就是在sidebar.php中加入的)加入下面代码,即可使用本评论插件啦~~
| < ?php |
| function get_recent_comments($no_comments = 8, $before = '<li> ', $after = '') { |
| global $wpdb, $tablecomments, $tableposts; |
| $request = "SELECT ID, post_title, comment_ID, comment_content, comment_author FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID AND (post_status = 'publish' OR post_status = 'static') AND comment_author != 'kimi'"; |
| $request .= "AND comment_approved = '1' ORDER BY $tablecomments.comment_date DESC LIMIT $no_comments"; |
| $comments = $wpdb->get_results($request); |
| $output = ''; |
| foreach ($comments as $comment) { |
| $post_title = stripslashes($comment->post_title); |
| $comment_author = stripslashes($comment->comment_author); |
| $comment_content = strip_tags($comment->comment_content); |
| $comment_content = stripslashes($comment_content); |
| $comment_excerpt =cutstr($comment_content,30); |
| $permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID; |
| $output .= $before . '<a href="' . $permalink . '" title="Comment By ' . $comment_author . '">' . $comment_excerpt . '</a>' . $after; |
| } |
| echo $output; |
| } |
| function cutstr($string, $length) { |
| if(strlen($string) < = $length) { |
| return $string; |
| } |
| $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string); |
| $strcut = ''; |
| $n = $tn = $noc = 0; |
| while($n < strlen($string)) { |
| $t = ord($string[$n]); |
| if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { |
| $tn = 1; $n++; $noc++; |
| } elseif(194 <= $t && $t <= 223) { |
| $tn = 2; $n += 2; $noc += 2; |
| } elseif(224 <= $t && $t < 239) { |
| $tn = 3; $n += 3; $noc += 2; |
| } elseif(240 <= $t && $t <= 247) { |
| $tn = 4; $n += 4; $noc += 2; |
| } elseif(248 <= $t && $t <= 251) { |
| $tn = 5; $n += 5; $noc += 2; |
| } elseif($t == 252 || $t == 253) { |
| $tn = 6; $n += 6; $noc += 2; |
| } else { |
| $n++; |
| } |
| if($noc >= $length) { |
| break; |
| } |
| } |
| if($noc > $length) { |
| $n -= $tn; |
| } |
| $strcut = substr($string, 0, $n); |
| $strcut = str_replace(array('&', '"', '< ', '>'), array('&', '"', '<', '>'), $strcut); |
| return $strcut; |
| } |
| ?> |

强烈建议把验证码去掉
你要是用wordpress你就知道评论是多少泛滥了。。。。
每天都有很多人发垃圾评论~~
想在这吐口口水好麻烦。。。。
我们交友吧!今天有缘访问贵网站,发现了谷歌广告,就履行义务认真学习了几遍。现在聪明人讨论作弊,我看不可取。作弊不光彩,是小人把戏。只要光明正大,才能成大功。谷歌有本事利用我们搞出大事业,我们也应该好好研究谷歌。这才是公平,这就是双赢。今天有幸认识了贵网站,我会每天义务性访问贵网站研究谷歌的,请你们也每天来我站坐片刻,关照一下我的谷歌(网址;http://shengyuan.lind.net邮箱;sy10088@yahoo.cn)。你们继续办好你们的网站,我继续扩大我的研究范围,每天在网上见面吧。预祝友情愉快!
楼上说的很好
嘎嘎
水水,你这个上插件不太会用,怎么使用.
要把上面那部分放哪文件,下面部分放那个文件,我菜,表骂俺!
都放到一个模板文件你需要显示最近评论的地方
水水,看到你的QQ处理忙碌状态,也不便打扰,还是在这给你留言吧,还是不知道怎么放,我放过以后是这样的效果,帮我看下www.hxxzclub.com/lgzawj
www.ccvita.com/usr/uploads/2007/11/sidebar.zip
这是我的侧边栏,楼上的去下载下看看吧
OK,谢谢水水,终于搞定
向博客主人学习,我是一刚刚学习上网冲浪的女生,很多东西都不太会,希望您可以多多传授,谢谢了!
wp2.5上不能使用啊大哥,怎么办??
不知道好用吗