WordPess调用最新评论插件
本文最后更新于 5984 天前,其中的信息可能已经有所发展或是发生改变。

想放个最新评论在首页显示,结果找了半天也没找到wordpress的调用最新评论的插件,很是郁闷~~~

算了,自己写个吧,这个是wordpress的调用最新评论的插件,大家可以看看~~

使用WordPess调用最新评论插件方法如下:

<div class="mod">
<h3>最新评论</h3>
<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;
}
?>

评论

  1. 16年前
    2007-11-09 19:48:15

    强烈建议把验证码去掉

  2. 博主
    16年前
    2007-11-09 21:30:32

    你要是用wordpress你就知道评论是多少泛滥了。。。。

    每天都有很多人发垃圾评论~~

  3. 16年前
    2007-11-10 2:41:59

    想在这吐口口水好麻烦。。。。

  4. 16年前
    2007-11-13 17:22:44

    我们交友吧!今天有缘访问贵网站,发现了谷歌广告,就履行义务认真学习了几遍。现在聪明人讨论作弊,我看不可取。作弊不光彩,是小人把戏。只要光明正大,才能成大功。谷歌有本事利用我们搞出大事业,我们也应该好好研究谷歌。这才是公平,这就是双赢。今天有幸认识了贵网站,我会每天义务性访问贵网站研究谷歌的,请你们也每天来我站坐片刻,关照一下我的谷歌(网址;http://shengyuan.lind.net邮箱;sy10088@yahoo.cn)。你们继续办好你们的网站,我继续扩大我的研究范围,每天在网上见面吧。预祝友情愉快!

  5. 博主
    16年前
    2007-11-13 23:30:31

    楼上说的很好

    嘎嘎

  6. 16年前
    2007-11-14 11:04:35

    水水,你这个上插件不太会用,怎么使用.
    要把上面那部分放哪文件,下面部分放那个文件,我菜,表骂俺!

  7. 博主
    16年前
    2007-11-14 12:51:39

    都放到一个模板文件你需要显示最近评论的地方

  8. 16年前
    2007-11-15 0:50:17

    水水,看到你的QQ处理忙碌状态,也不便打扰,还是在这给你留言吧,还是不知道怎么放,我放过以后是这样的效果,帮我看下www.hxxzclub.com/lgzawj

  9. 博主
    16年前
    2007-11-15 9:18:40

    http://www.ccvita.com/usr/uploads/2007/11/sidebar.zip
    这是我的侧边栏,楼上的去下载下看看吧

  10. 16年前
    2007-11-15 15:58:29

    OK,谢谢水水,终于搞定

  11. 16年前
    2008-3-11 15:49:42

    向博客主人学习,我是一刚刚学习上网冲浪的女生,很多东西都不太会,希望您可以多多传授,谢谢了!

  12. 16年前
    2008-6-29 2:41:32

    wp2.5上不能使用啊大哥,怎么办??

  13. ceshi
    12年前
    2011-11-14 2:04:38

    不知道好用吗

  14. 10年前
    2013-10-08 14:57:52

    我加了,但是还是不起作用,我对代码可以说真的是一窍不通啊,请求给予指点1、2,我的网站:品核桃网http://www.pinhetao.com/,用了有言的评论插件,功能是整强大了,不过wordpress调用不出来了

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇