roga’s recent comments – WordPress Plugin

因為 WordPress 內建 wp-include/widgets.php 的 recent-comments 不會顯示該筆 comment 的內容,為了不破壞 WordPress 的完整性,所以我決定自己寫一個 Widget ,然後用 Plugin 的方式載入,這樣可以不用動到 Theme ,又能自訂參數(標題、回應筆數、以及回應摘要字數)。

這個程式主要是參考 WordPress 的 widgets.php 和兩個 Recent Comments Plugins (包含了 bdp-comments 以及 Recent Comments and Trackbacks) 還有官方的 Codex

功能說明:

  1. 可以直接從後台修改 Widget 設定,分別是標題、「顯示回應數目」以及「回應長度」
  2. 顯示 Comment (回應), Trackback(接收到的引用通知), Pingback(發送的引用通知)
  3. 支援直接在 sidebar 插入: ,表示顯示 5 筆回應,每筆回應有 50 個字。

安裝步驟:

  1. 使用 ftp 將檔案上傳到 wp-content/plugins/ 目錄內
  2. 登入 WordPress 後台
  3. 啟用 roga-recent-comments Plugin
  4. 在佈景主題的 Widget 可以進行修改

Cause of the widget “recent-comment” that WordPress provided couldn’t show the commet content, so I decided to write one plugin and make it widgetable. You can set the number of comments ,how many words to excerpt and title in the control panel.

About this widget, I’ve learned some useful skill from bdp-comments 以及 Recent Comments and Trackbacks. Thanks Them.

Functions:

  1. Modify the “number of comments” ,”how many words to excerpt”, and “title” in the control panel.
  2. show Comments. Trackback or Pingbacks.
  3. Support insert the statement: “Directly”, this example means “roga-recent-comment” will retrieve 5 recent comments, and excerpt 50 characters.

Installation:

  1. Upload the file to wp-content/plugins/ via FTP
  2. Login in your WordPress control panel
  3. Activate the roga-recent-comments Plugin
  4. You can modify it in Presentation -> Widgets.

備註:本簡短程式採用 GPLv2 授權:「歡迎隨意使用,當重新散佈或修改的時候請同時公佈原始碼。」

下面是原始程式,複製下來貼成一個 PHP 檔即可。

[crayon language=’php’]
comments,$wpdb->posts WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID “;
$sql .= “AND comment_approved=’1′ AND $wpdb->posts.post_status=’publish’ AND $wpdb->posts.post_password=” ORDER BY $wpdb->comments.comment_date DESC LIMIT $comment_num”;

$comments=$wpdb->get_results($sql);

foreach ($comments as $comment)
{
$comment_author = stripslashes($comment->comment_author);
$comment_content = stripslashes($comment->comment_content);

$comment_content = strip_tags(str_replace(‘…’, ‘.’, $comment_content));
$comment_excerpt = mb_substr($comment_content, 0, $excerp_length, get_bloginfo(‘charset’));
$comment_excerpt.= ‘…’;

$permalink=get_permalink($comment->ID).”#comment-“.$comment->comment_ID;

if($comment_author==”roga”)
echo “

  • $comment_author :

  • Posted in WordPress
    0 comments on “roga’s recent comments – WordPress Plugin
    1 Pings/Trackbacks for "roga’s recent comments – WordPress Plugin"
    1. […] Plugin 用來讀取 Recents Comment ,叫做 roga’s recent comments – WordPress Plugin 。當時取出的 SQL Statements 只有考慮 comment_approved (這是有沒有被 moderate […]

    Leave a Reply

    Your email address will not be published.