Get Recent Comments

看到大家幾乎都有Recent Comment,讓我也很想來一下。從Blake那邊看來一個叫做Get Recent Comments的plug-in。和很多Wordpress plug-in一樣,都不是直接activate就完全沒事的東西。

使用Wordpress 1.5版,配合Get Recent Comments 1.2版,要deactivate才有作用的問題沒遇到,倒是有option page無法顯示,以及wordwrap對utf8處理的問題,經過patch之後已經搞定。以下是我的步驟:

1.在plug-in page先activate,然後在sidebar.php中加入類似以下的片斷:

<?php if(is_home()&&function_exists('get_recent_comments')) {?>
<li>
<h2><?php _e('Recent Comments'); ?></h2>
<ul>
<?php get_recent_comments();?>
</ul>
</li>
<?php }?>


2.將get-recent-comments.php內
if ( function_exists("is_plugin_page") && is_plugin_page() ) {
kjgrc_options_page();
return;

換成
add_action('options_page_get-recent-comments', 'kjgrc_options_page');
可解決option page無法顯示的問題。

3.將內建的wordwrap() function用以下function取代(from php.net討論區):
function utf8_wordwrap($str,$len,$what){
# usage: utf8_wordwrap("text",3,"n");
# by tjomi4`, thanks to SiMM.
# www.yeap.lv
$from=0;
$str_length = preg_match_all('/[x00-x7FxC0-xFD]/', $str, $var_empty);
$while_what = $str_length / $len;
while($i < = round($while_what)){
$string = preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'.
'((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s',
'$1',$str);
$total .= $string.$what;
$from = $from+$len;
$i++;
}
return $total;
}


可解決斷字破壞utf8字元的問題。

搞定,可是其實也沒人在看我的blog,不知道在爽什麼東西XD

Update: 我終於也遇到comment太長的問題,根據Jerome的修正我也更新了,這邊有更新好的版本,可以自行下載取用。

Update2: 檔案更新至1.4版含cache功能,修正cache在中文環境下只顯示一個a的問題。

留言

  1. 有人看啊!我常來潛水。

    回覆刪除
  2. 我是路過 , 當然也要看啊 !

    原來 Live preview 是這回事 !
    不留言還不知道是什麼東東呢 !
    來去抓回套上看看 ,多謝 !

    回覆刪除
  3. [...] 目前網站的Recent comments一欄採用的是get recent comments的plugin,主系統是wordpress 1.5.2版。曾經為了修理中文字斷行問題,參考了PRIV的修改說明,更改部分的程式碼,並且一切運作正常。 [...]

    回覆刪除
  4. Recent Comments 修理日誌...


    recent comments出現錯誤訊息:Compilation failed: regular expression too large at offset 0 in ….

    目前網站的Recent comments一欄採用的是get recent commentsçš„plugin,ä...

    回覆刪除
  5. 我現在用的版本,把選項裡面的Wrap long words at: characters,調到40,就沒有斷字問題了,不過沒仔細測過就是了。

    回覆刪除
  6. 这个插件不管我用官方的版本,还是你这里提供的下载,都没办法在后台选项里显示出recent comment的设置界面。快被它搞疯了。也不是上面提到的add_action('options_page_get-recent-comments', 'kjgrc_options_page');问题。因为最新的版本已经改正了这个BUG也不行。我用的是wp2.0.5,空间IIS+PHP 5.1.6 .希望你能解答一下。谢谢!

    回覆刪除
  7. 抱歉,老實說我不曉得。

    對php不熟,我也只會到處亂插die看看某些地方是不是真的有被跑到。以下是比較可疑的地方,我稍微修改一下,你試試看。

    1.win32處理basename的問題,拿掉basename看看,我看其它plug-in多半只用__FILE__而沒有用basename(__FILE__)。
    2.他的$wp_version沒有宣告global,所以$wp_version永遠不會>1.5,不過不曉得少了hook function有什麼影響。

    以下是改好的程式片段。


    function kjgrc_add_options_page()
    {
    global $wp_version;
    if (function_exists('add_options_page')) {
    // WordPress 1.5 sometimes doesn't show the options page if called in the first style
    if ( $wp_version > "1.5" ) {
    add_options_page('Get Recent Comments Plugin', 'Recent Comments', 8, __FILE__ ,'kjgrc_options_page');
    } else {
    add_options_page('Get Recent Comments Plugin', 'Recent Comments', 8, __FILE__);
    }
    }
    }


    再不行我也不曉得,因為記得以前在win32下用wamp也沒有遇到什麼大問題,不曉得你那邊的環境怎樣。

    回覆刪除
  8. [...] 放上修改好的檔案,也包括之前的修正,有興趣的就取用吧。 引用時請使用此URL [...]

    回覆刪除

張貼留言

這個網誌中的熱門文章

為什麼男生唱女生的歌要升 key

台灣工程師常唸錯的英文單字

談談台灣人使用統傳漢字的優越心態