我們的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>';
- }
- }
新聞熱點
疑難解答
圖片精選