wordpress小工具最新评论显示评论内容

lisahost.com

wordpress默认的侧边栏有个 最新评论 小工具,其默认不显示评论内容,下面是修改后可以显示评论作者和评论内容的。
修改文件:wp-includes/default-widgets.php
找到:

if ( $comments ) {
	// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
	$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
	_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
	foreach ( (array) $comments as $comment) {
		$output .=  '<li>' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
	}
}

改为:

if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= ‘<li class=”recentcomments”>’ . /* translators: comments widget:
1: comment author, 2: post link */ sprintf(_x(‘%1$s : %2$s’, ‘widgets’),
get_comment_author_link(), ‘<a href=”‘ . esc_url( get_comment_link($comment->comment_ID) ) . ‘”>’ . mb_strimwidth(strip_tags($comment->comment_content),0,46,”,’utf-8′) . ‘</a>’) . ‘</li>’;
}
}

显示效果如下:
侧边栏评论

    所有主机信息仅是为及时分享并收录,不做推荐!