默认的近期评论只显示评论人文章标题,看起来不太爽。修改了一下

vim class-wp-widget-recent-comments.php 打开这个文件编辑
找到下面代码:

$output .= ‘<li class="recentcomments">’;
/* translators: comments widget: 1: comment author, 2: post link */
$output .= sprintf( _x( ‘%1$s on %2$s’, ‘widgets’ ),
‘<span class="comment-author-link">’
. get_comment_author_link( $comment ) . ‘</span>’,
‘<a href="’ . esc_url( get_comment_link( $comment ) ) . ‘">’ .
get_the_title( $comment->comment_post_ID ) . ‘</a>’);
$output .= ‘</li>’;

改成:

$output .= ‘<li class="recentcomments">’;
/* translators: comments widget: 1: comment author, 2: post link */
$comment_content = $comment->comment_content;
$sub_commnet = mb_substr(strip_tags($comment_content), 0, 100, ‘utf-8’);
$comment_len = strlen($comment_content);
$output .= sprintf( _x( ‘%1$s %2$s’, ‘widgets’ ),get_comment_author( $comment ).’ ‘
.’在 <a href="’ . esc_url( get_comment_link( $comment ) ) . ‘">’
.get_the_title($comment->comment_post_ID) . ‘</a> 说 ‘,
$comment_len <=100? $comment_content:$sub_commnet. ‘…’);
$output .= ‘</li>’;

修改适用于wordpress v4.6,其他版本没试过。

最后修改:2019 年 02 月 23 日
如果觉得我的文章对你有用,请随意赞赏