修改WordPress 2.8最新迴響的顯示格式

H0998

果你的WordPress 2.8使用的Recent comment(最新迴響或最新留言)是系統內建的模組的話,它顯示的格式會是「留言人 在 文章標題」的格式,在此種格式下,必須點擊文章標題的連結,才能看到實際的留言內容,為了能直接顯示留言內容,我修改了下列幾段程式:

  1. 修改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)
  2. 因為系統取留言片段的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);
    }

    ##

##

您可能也會有興趣的類似文章

填寫回應

 

 

 

您可使用這些HTML標籤

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

隨機文章

  1. [Tools] 常駐式的記事本工具:AM-NoteBook 
  2. [轉貼電腦報] HiNet借重年輕思維推廣Xuite (2)
  3. [Tools] 吃飯皇帝大:決定餐廳的輪盤軟體 Wheel ’O Yum (1)
  4. 衛星雲圖程式更新–修改2 (8)
  5. TiddlyWiki:「所見即所得」式的編輯插件 (2)
  6. 重新排列右鍵功能表(Context Menu)的選項 
  7. 附中71學年度畢業班紀念休閒服 (3)
  8. jQuery TreeView插件IE異常解決方法 
  9. 我的血淚力作之《站長親授!WordPress 3.0部落格架站十堂課》 (3)
  10. [WordPress外掛] 顯示外部連結小圖示以方便辨識 (2)

歷史熱門文章

  1. 如何手動輸入Plurk的表情圖示? (352,041 點擊/2008-09-29)
  2. 簡單放大Plurk輸入區的方法[修訂] (86,779 點擊/2008-09-29)
  3. Plurk CSS樣式自訂修改全攻略 (82,772 點擊/2009-07-04)
  4. 啟用&關閉中華電信ZyXEL P874的無線網路連線功能的步驟[修訂] (82,425 點擊/2011-06-01)
  5. 網路升級光世代50M/3M與設定ZyXEL P874 (52,421 點擊/2011-05-28)
  6. 輕鬆學會彈指神功-揭露AutoHotkey絕技 (42,815 點擊/2008-04-10)
  7. iPad新手入門技巧 (39,997 點擊/2011-02-05)
  8. 分享世博台灣館主題曲『台灣的心跳聲』MV(附歌詞+下載連結+新歌詞) (38,040 點擊/2010-04-27)
  9. 把HTC Touch HD操作介面換成Spb Mobile Shell,美觀又便利! (37,864 點擊/2009-02-18)
  10. 另一套適用手機的影片轉檔工具:WinAVI 3GP/MP4/PSP/iPod Video Converter (35,797 點擊/2009-04-18)