Hirobee’s Trail [Memorandum]

Recently Commented part2

by Hirobee on 04:00 Tuesday, March 22nd, 2005, under Plugin, WordPress

tkzy_get_recent_commentsで表示される順番が、

  • エントリがポストされた日時 -> コメントされた日時(同じ日にコメントがあった場合、コメントされた時間が遅くてもポストされた日付が新しいものが上)に並んでしまう

という微妙に気になる状態だったのでので修正してみました。
それと、承認前のコメントが表示されてしまうところも修正しました。

tkzy_get_recent_comments.phpはtkzy::blog ≫ また修正にあるものです。
ソースに書かれている順に以下のように修正しました。

  1. 承認前のコメントが表示されないようにするために、5行目に太字斜体部分を追加する。

    $comments = $wpdb->get_results("SELECT ID, post_title, post_date, omment_ID,
    comment_author,comment_author_url, comment_author_email, comment_date FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID AND $tablecomments.comment_approved='1' ORDER BY $tablecomments.comment_date DESC LIMIT $limit");

  2. 並び順の変更するために、9行目の$aと$bを入れ替える。

    return mysql2date('U',$b->comment_date)
    - mysql2date('U',$a->comemnt_date);

今回の修正は、りょ! ≫ 最近のコメントI know. 開発日誌、≫ WordPress 最近のコメントを参考にしました。ありがとうございました。

March 22, 2005 @ 22:56 追記
:: plasticdreams :: ≫ hack the tkzy get recent commentsをみて、Pluginにしてみました。
Plugin Name:(Pluginの名前)、Plugin URI:(配布元のURI)、Description:(説明)、Author:(作者名)、Author URI:(作者のURI)を1行目の<?phpの次の行から、/* */で囲んでコメントとして書いて、/wp-content/pluginにコピーし、管理ページでPluginをActivateすれば完了。
こうすれば、Recently Commentedで書いた1行目のrequire_onceは必要なくなります。

March 25, 2005 @ 15:36 追記
「2. 並び順の変更」を修正しました。
9行目のcomment_date2箇所をpost_dateに修正

return mysql2date('U',$a->post_date)
- mysql2date('U',$b->post_date);

11行目のpost_date2箇所をcomment_dateに修正

return mysql2date('U',$b->comment_date)
- mysql2date('U',$a->comment_date);

この修正をすると、コメントがつくとそのエントリが単独で並んでしまい、tkzy_get_recent_commentsの本来の動作と変わってしまうためです。

:,

Leave a Reply


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!