解决了SIDEBAR WIDGET中recent comments的显示问题
现在不会只显示"什么日志上面的什么人",而是会显示回复预览。
这么简单,改个sql,改两句显示语句就行了
重点是这个函数:
- <?php
- //hacked by JerryHong
- 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' );
- }
- ?>
- <?php echo $before_widget; ?>
- <?php echo $before_title . $title . $after_title; ?>
- <ul id="recentcomments"><?php
- if ( $comments ) : foreach ($comments as $comment) :
- echo '<li class="recentcomments">' . sprintf(__('%2$s--%1$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '" title='.$comment->comment_content .'>' . mb_substr($comment->comment_content,0,26,'UTF-8'). '</a>') . '</li>';
- endforeach; endif;?></ul>
- <?php echo $after_widget; ?>
- <?php
- }






你好!怎么让Recent Comments 、Recent Posts显示固定的字符,10字的仅仅让它显示5个 。应该修改哪个文件?我刚接触wp。
@qg:
wp-includes/widgets.php.
WP默认的显示确实太丑了;)
能告诉具体改一个语句吗?让它最新文章标题只显示15个字符,评论格式同你站一样!
在function wp_widget_recent_entries($args)里,试试substr(the_title(),0,15);
若中文出现乱码可参考我文章里那个mb_substr()函数
忘记跟你说了, 我php还未入门!根本就不知道substr(the_title(),0,15);应该放哪里?
服了……把这个载下来解压覆盖wp-includes\widgets.php
http://www.JerryHong.com/wp-content/uploads/widgets.rar
如果需要微调请改698行的那个15
如果还有乱码……看来我解决不了了
乱码没发生。但对数字截取敏感!后把GB2312改成UTF-8后就正常了!呵呵!thanks!
我想问一下,如何让wp自带的widget中recent comments不要显示trackback和ping? 你可以访问我的站点,看看右上角,我只想显示comments, 但是wp自作主张地把trackback/ping都显示出来了。
谢谢
请修改wordpress/wp-includes/widgets.php的第878行
改成
应该就行了
如果想显示评论内容请参考上面的附件……
PS.域名不错