wordpress中最新评论的显示样式看起来很不爽,至少我这么觉得,以auther on+ article的形式,没有直接显示评论的内容。
如果要修改的话,从网上找了很多资料,但是看起来都很复杂,而且版本不一样,修改方法也不是太一样,我的修改方法是基于wordpress2.8.5来修改的,主要是直接修改源码,找到wp-includes/default-widgets.php,搜索WP_Widget_Recent_Comments这个类,修改function widget( $args, $instance ) 方法为如下形式:

function widget( $args, $instance ) {
		global $wpdb, $comments, $comment;
 
		extract($args, EXTR_SKIP);
		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
		if ( !$number = (int) $instance['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 * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15");
			wp_cache_add( 'recent_comments', $comments, 'widget' );
		}
 
		$comments = array_slice( (array) $comments, 0, $number );
?>
		<?php echo $before_widget; ?>
			<?php if ( $title ) echo $before_title . $title . $after_title; ?>
			<ul id="recentcomments"><?php
			///修改最新评论内容
			if ( $comments ) : 
				foreach ( (array) $comments as $comment) :
				$comment_content = strip_tags($comment->comment_content);
				$comment_content = stripslashes($comment_content);
 
				$comment_excerpt =substr($comment_content,0,50);
				$comment_excerpt = my_utf8_trim($comment_excerpt);
				echo  '<li class="recentcomments">' . sprintf(__('%1$s: %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '" title="'. get_the_title($comment->comment_post_ID) .'">' . $comment_excerpt .'...'. '</a>') . '</li>';
				endforeach; 
			endif;?></ul>
 
		<?php echo $after_widget; ?>
<?php
	}

本文地址:http://www.yaronspace.cn/blog/index.php/archives/117

来自yaronspace.cn  本文链接:http://yaronspace.cn/blog/archives/117