
如果你的WordPress 2.8使用的Recent comment(最新迴響或最新留言)是系統內建的模組的話,它顯示的格式會是「留言人 在 文章標題」的格式,在此種格式下,必須點擊文章標題的連結,才能看到實際的留言內容,為了能直接顯示留言內容,我修改了下列幾段程式:
- 修改wp-includes\default-widgets.php 第645行,把get_the_title換成get_comment_excerpt;要注意檔案編碼要存成UTF-8,以免中文字變成亂碼:
echo '<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) ) . '">' . get_comment_excerpt() . '</a>') . ''; // get_the_title($comment->comment_post_ID) - 因為系統取留言片段的get_comment_excerpt函數是針對拚音文字在處理的,中文不甚適用,因此一併修改wp-includes\comment-template.php 第386行:
function get_comment_excerpt() { global $comment; $comment_text = strip_tags($comment->comment_content); /* $blah = explode(' ', $comment_text); if (count($blah) > 20) { $k = 20; $use_dotdotdot = 1; } else { $k = count($blah); $use_dotdotdot = 0; } $excerpt = ''; for ($i=0; $i< $k; $i++) { $excerpt .= $blah[$i] . ' '; $excerpt .= $blah[$i] . ' '; } */ if (strlen($comment_text) > 40) { $excerpt = mb_substr($comment_text,0,40) . '...'; } else { $excerpt = $comment_text; } //$excerpt .= ($use_dotdotdot) ? '...' : ''; return apply_filters('get_comment_excerpt', $excerpt); }##
##
您可能也會有興趣的類似文章
- Step by Step安裝WordPress 3.0與啟用 Multi-Site多站點功能 (14則留言, 2010/07/10)
- 用jQuery改造WordPress網頁 (2則留言, 2009/10/27)
- [WordPress] 使用Anchor在目前網頁裡瞬間移動 (0則留言, 2008/11/30)
- 自製WordPress-mu 2.7的繁體中文語言檔[修訂] (10則留言, 2009/02/09)
- 慎始之:如何挑選適當的WordPress固定網址(Permalink) (2則留言, 2010/07/03)
- [WordPress] 更換固定網址(permalink)格式為文章標題 (4則留言, 2008/12/01)
- WordPress減肥記:壓縮JavaScript檔的大小 (6則留言, 2010/06/08)
- 自動產生文章目錄的WordPress外掛:jQuery Table of Contents (2則留言, 2010/06/13)
- WordPress簡單又美觀的網站訂閱與文章書籤外掛:Add To Any (1則留言, 2008/12/28)
- 最具彈性的WordPress樣版引擎Atahualpa 3.5.1-超神奇! (7則留言, 2010/07/04)
- [WordPress 3] 修改Twenty Eleven佈景主題在iPad瀏覽側邊欄的問題 (1則留言, 2012/01/23)
- WordPress 3.0與PHP 5的時區問題 (1則留言, 2010/06/24)
- WordPress 3.1無法正常顯示分類的修正步驟 (1則留言, 2011/02/28)
- WordPress持續減肥-找出使用網站內部圖檔的文章 (0則留言, 2010/06/12)
- WordPress跑馬燈外掛:Running Line (1則留言, 2010/06/10)














