正在加载...
2006-10
6
发表于: 未分类 | 作者: xurenlu
标签:

用法:将deskor_comments.php传到wp-contents/plugins目录,然后在插件管理中激活。
在需要显示最新评论的地方,比发themes/你的风格名称/sitebar.php中加:

  1. <?php
  2. /**
  3. 25是调用最新评论的条数。
  4. 先判断一下是否已经包含了插件文件,函数是否存在,免得出错。
  5. */
  6. if(function_exists ("get_deskor_comments"))
  7.  get_deskor_comments(25);
  8. ?>

deskor_comments.php文件的内容:

  1. <?php
  2. /*
  3. Plugin Name: deskor_comments
  4. Plugin URI: http://www.162cm.com
  5. Description: 一个显示最新评论的插件<br/>调用方法:在需要显示的地方写上:<?php get_deskor_deskor_comments(10);?>
  6. Author: renlu xu <helloasp@hotmail.com>
  7. Version: 1.0
  8. Author URI: http://www.162cm.com
  9. */
  10.  
  11.  
  12. function get_deskor_comments($count=10)
  13. {
  14.     global $wpdb;
  15.      $res=$wpdb->get_results("SELECT * FROM $wpdb->comments order by comment_ID  DESC limit ".$count);
  16.      foreach($res as $row)
  17.      {
  18.     
  19.          echo "<li>";
  20.          echo "<a href=\"".get_permalink($row->comment_post_ID)."#comment-".$row->comment_ID."\">[";
  21.          echo $row->comment_author."]says(".xoops_substr($row->comment_content,0,45);
  22.          echo ")</a></li>";
  23.         
  24.      }
  25. }
  26.  
  27.  
  28.  
  29.  
  30.     /**
  31.     截取函数,从xoops中挪过来的.
  32.     */
  33.     function xoops_substr($str, $start, $length, $trimmarker = '...')
  34. {
  35.  
  36.     if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
  37.         $str2 = mb_strcut( $str , $start , $length - strlen( $trimmarker ) );
  38.         return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
  39.     }
  40.     // phppp patch
  41.     $DEP_CHAR=127;
  42.     $pos_st=0;
  43.     $action = false;
  44.     for ( $pos_i = 0; $pos_i < strlen($str); $pos_i++ ) {
  45.         if ( ord( substr( $str, $pos_i, 1) ) > 127 ) {
  46.             $pos_i++;
  47.         }
  48.         if ($pos_i<=$start) {
  49.             $pos_st=$pos_i;
  50.         }
  51.         if ($pos_i>=$pos_st+$length) {
  52.             $action = true;
  53.             break;
  54.         }
  55.     }
  56.     return ($action) ? substr( $str, $pos_st, $pos_i - $pos_st - strlen($trimmarker) ) . $trimmarker : $str;
  57. }
  58.  
  59.  
  60.  
  61. ?>

: http://www.162cm.com/archives/274.html

本文相关评论 - 1条评论都没有呢

还没有评论。