修改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);
    }

    ##

##

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

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *