2006-10
6
用法:将deskor_comments.php传到wp-contents/plugins目录,然后在插件管理中激活。
在需要显示最新评论的地方,比发themes/你的风格名称/sitebar.php中加:
- <?php
- /**
- 25是调用最新评论的条数。
- 先判断一下是否已经包含了插件文件,函数是否存在,免得出错。
- */
- if(function_exists ("get_deskor_comments"))
- get_deskor_comments(25);
- ?>
deskor_comments.php文件的内容:
- <?php
- /*
- Plugin Name: deskor_comments
- Plugin URI: http://www.162cm.com
- Description: 一个显示最新评论的插件<br/>调用方法:在需要显示的地方写上:<?php get_deskor_deskor_comments(10);?>
- Author: renlu xu <helloasp@hotmail.com>
- 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 "<li>";
- echo "<a href=\"".get_permalink($row->comment_post_ID)."#comment-".$row->comment_ID."\">[";
- echo $row->comment_author."]says(".xoops_substr($row->comment_content,0,45);
- echo ")</a></li>";
- }
- }
- /**
- 截取函数,从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;
- }
- ?>
还没有评论。