WordPress文章显示评论内容而不是标题

作者:袖梨 2022-06-25

 

首先找到根目录下的 wp_includes/default-widgets.php,在functionwidget`(第625行左右)里面找

到以下代码(第655行左右):

 代码如下 复制代码

if ( $comments ) {
     foreach ( (array) $comments as $comment) {
     $output .= '

' . /* translators: comments widget: 1: comment

author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(),

'' . get_the_title

($comment->comment_post_ID) . '') . '

';
     }
}

将第三行中的

 代码如下 复制代码

get_the_title($comment->comment_post_ID) 改成 strip_tags( $comment-

>comment_content),

同时将sprintf里的on改成你想要显示的文字,如『说』,这样样式就变成

『评论者』说『评论内容』 以下是修改后的代码(注意:修改代码前请先备份)

 代码如下 复制代码

if ( $comments ) {
     foreach ( (array) $comments as $comment) {
     $output .= '

' . /* translators: comments widget: 1: comment

author, 2: post link */ sprintf(_x('%1$s said: %2$s', 'widgets'), get_comment_author_link

(), '' . strip_tags

(($comment->comment_content) . '') . '

';
     }
}

其实这个$output就是输出html代码,所以可以在此根据自己的需要作出修改。

相关文章

精彩推荐