飘渺的人生

开拓人生 追求梦想

站内搜索


日志归档

赞助商链接

正在加载广告单元...

Support

  • 正在加载图片...

Feed™

我的相册

[slideshow=2,150,150]
Oct
12

WordPess调用最新评论插件

Posted in » admin
2 hits

想放个最新评论在首页显示,结果找了半天也没找到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(’&amp;’, ‘&quot;’, ‘&lt;’, ‘&gt;’), 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(’&amp;’, ‘&quot;’, ‘&lt;’, ‘&gt;’), $strcut);

return $strcut;
}
?>

相关文章:

在此发表评论/留言

One Response to “WordPess调用最新评论插件”

这篇是测试WP的文章

admin on Oct 12, 2008 19:45 | 回复该评论

Powered by WordPress