用法:将deskor_comments.php传到wp-contents/plugins目录,然后在插件管理中激活。 在需要显示最新评论的地方,比发themes/你的风格名称/sitebar.php中加: deskor_comments.php文件的内容: 调用方法:在需要显示的地方写上: Author: renlu xu Version: 1.0 Author URI: http://www.162cm.com */ function get_deskor_comments($count=10) { global $wpdb; $res=$wpdb->get_results(“SELECT * FROM $wpdb->comments order by comment_ID DESC limit “.$count); foreach($res as $row) { echo “* “; echo “comment_post_ID).”#comment-“.$row->comment_ID.””>[“; echo $row->comment_author.”]says(“.xoops_substr($row->comment_content,0,45); echo “)
“; } } /** 截取函数,从xoops中挪过来的. */ function xoops_substr($str, $start, $length, $trimmarker = ‘…’) { if (function_exists(‘mb_internal_encoding’) && @mb_internal_encoding(_CHARSET)) { $str2 = mb_strcut( $str , $start , $length - strlen( $trimmarker ) ); return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : ‘’ ); } // phppp patch $DEP_CHAR=127; $pos_st=0; $action = false; for ( $pos_i = 0; $pos_i < strlen($str); $pos_i++ ) { if ( ord( substr( $str, $pos_i, 1) ) > 127 ) { $pos_i++; } if ($pos_i<=$start) { $pos_st=$pos_i; } if ($pos_i>=$pos_st+$length) { $action = true; break; } } return ($action) ? substr( $str, $pos_st, $pos_i - $pos_st - strlen($trimmarker) ) . $trimmarker : $str; } ?>