好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

我们的wordpress默认情况下只显示评论的标题而不是显示评论内容,下面我来调整一下让wordpress显示评论内容吧,具体操作步骤如下.

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

if  (  $comments  ) {        foreach  ( ( array )  $comments   as   $comment ) {        $output  .=  '<li class="recentcomments">'  .  /* 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>' ;       }  } 

将第三行中的如下代码:

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

同时将sprintf里的on改成你想要显示的文字,如『说』,这样样式就变成『评论者』说『评论内容』 以下是修改后的代码(注意:修改代码前请先备份)

实例代码如下:

if  (  $comments  ) {        foreach  ( ( array )  $comments   as   $comment ) {        $output  .=  '<li class="recentcomments">'  .  /* translators: comments widget: 1: comment   author, 2: post link */  sprintf(_x( '%1$s said: %2$s' ,  'widgets' ), get_comment_author_link  (),  '<a href="'  . esc_url( get_comment_link( $comment ->comment_ID) ) .  '">'  .  strip_tags   (( $comment ->comment_content) .  '</a>' ) .  '</li>' ;       }  } 

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

查看更多关于WordPress文章显示评论内容而不是标题 - WordPress的详细内容...

  阅读:51次