重生西汉末年小说:让WordPress的最近评论Widget直接显示评论内容
来源:百度文库 编辑:偶看新闻 时间:2024/05/02 20:08:16
WordPress自带的最近评论Widgts显示的效果是 someone on postname,但不少人希望让它显示为someone says: something。修改WordPress的/includes/widgets.php可以达到目的。
打开widgets.php文件,首先添加一个自定义函数my_utf8_trim()(取于WordPress中文工具箱),用于截断从数据库取出来的评论字符串。
- function my_utf8_trim($str)
- {
- $len = strlen($str);
- for ($i=strlen($str)-1; $i>=0; $i-=1)
- {
- $hex .= ' '.ord($str[$i]);
- $ch = ord($str[$i]);
- if (($ch & 128)==0) return(substr($str,0,$i));
- if (($ch & 192)==192) return(substr($str,0,$i));
- }
- return($str.$hex);
- }
接下来修改函数wp_widget_recent_comments($args)(以WordPress 2.3.2 为例):
- function wp_widget_recent_comments($args)
- {
- global $wpdb, $comments, $comment;
- extract($args, EXTR_SKIP);
- $options = get_option('widget_recent_comments');
- $title = empty($options['title']) ? __('Recent Comments') : $options['title'];
- if ( !$number = (int) $options['number'] )
- $number = 5;
- else if ( $number < 1 )
- $number = 1;
- else if ( $number > 15 )
- $number = 15;
- if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) )
- {
- $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
- wp_cache_add( 'recent_comments', $comments, 'widget' );
- }
- ?>
- if ( $comments ) : foreach ($comments as $comment) :
- echo '
- ' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '' . get_the_title($comment->comment_post_ID) . '') . ' ';
- endforeach; endif;?>
- }
将其整体整改为:
- function wp_widget_recent_comments($args)
- {
- global $wpdb, $comments, $comment;
- extract($args, EXTR_SKIP);
- $options = get_option('widget_recent_comments');
- $title = empty($options['title']) ? __('Recent Comments') : $options['title'];
- if ( !$number = (int) $options['number'] )
- $number = 5;
- else if ( $number < 1 )
- $number = 1;
- else if ( $number > 15 )
- $number = 15;
- if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
- $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID,comment_content FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
- wp_cache_add( 'recent_comments', $comments, 'widget' );
- }
- ?>
- if ( $comments ) : foreach ($comments as $comment) :
- $comment_content = strip_tags($comment->comment_content);
- $comment_content = stripslashes($comment_content);
- $comment_content = preg_replace('/\[qu(.(?!\[\/quote]))+.\[\/quote]/si', '', $comment_content);
- $comment_content = preg_replace('/\s*:em\d\d:\s*/si', '', $comment_content);
- $comment_excerpt =substr($comment_content,0,50);
- $comment_excerpt = my_utf8_trim($comment_excerpt);
- echo '
- ' . sprintf(__('%1$s:%2$s'), get_comment_author_link(), '' . $comment_excerpt .'...'. '') . ' ';
- endforeach; endif;?>
- }
最后说一句,记得把文件另存为UTF8格式,因为我给出的修改代码中有一个中文冒号:)
谁知道一个偷金币的游戏widge
最近的新闻加评论
关于Wordpress的使用问题...
谁会装Wordpress 的BLOG?
在WordPress中插入WMA的方法
wordpress 的blog 安装不上
my.donews.com中wordpress的用法
求wordpress 的相册Gallary2插件
篮球迷们对火箭队最近比赛的评论
谁能评论一下最近央视播的《玉碎》?
如何在wordpress顶部的logo上放swf文件?
可以提供wordpress的中文说明很中午语言包吗?
国内有哪些提供wordpress服务的免费bsp
关于wordpress
怎样在网上发表自己的作文,让大家评论?
为什么我的DONEWS的BLOG中的最近评论是以前的?
求对最近发生的有关产业经济事件的评论
最近太平洋网上在沸沸扬扬的评论佳能A620,都说进灰 的情况比较严重
最近发现新浪的评论速度特别快,是使用了什么技术啊?
最近MSN的spaces是不是改版了?为什么不能评论了?
谁能帮忙介绍一个较为便宜的支持WordPress 2.0.2的空间服务商?
谁能告诉我wordpress 最新中文版在哪儿有下的啊?
谁能告诉我wordpress 最新中文版在哪儿有下的啊?
为什么我的WordPress插入图片后不能显示原大小,而只是缩略图?