e.b.i.f
  • Photo-Biyori
  • about
  • bookmarks
  • skip to menu ↓

2009/01/26 (Mon)

WP 2.7 のコメント返信機能を導入してみた。

Photo-Biyoriのアップデートに向けてのテストがてら、このサイトのコメント表示を2.7から導入された返信できる入れ子(って言うんでしょうか?)/スレッド表示にしてみました。

いろいろ探してみたのですが、詳しいドキュメンテーションが見当たらず、以下を参考に無理矢理挑戦。
WordPress Codex: Template Tags/wp list comments
WordPress Codex: Migrating Plugins and Themes to 2.7/Enhanced Comment Display

結構めんどくさかったので、「別に今のままでもいいや」っていう方は、使っているテーマの作者が2.7対応にアップデートしてくれるのを待ったほうがいいかも。参考になるかどうかわかりませんが、以下私がこのサイトに導入した方法です。

まず、使用しているテーマのheader.phpファイルのwp_head()の直前に

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

というラインを追加。

管理画面の設定 > ディスカッションから
Enable threaded (nested) comments x levels deep
というのをチェック。

次に。テーマ内のcomments.phpというファイルが今回のアップデートで大幅に変更されているようで、あれこれいじってもちゃんと動作しなかったので、自分のテーマのcomments.phpをいったんバックアップして、2.7に同梱されているデフォルトテーマのcomments.phpを自分のテーマ内にコピー。この時点でスタイルが設定されていないのでレイアウトが一時ぐちゃぐちゃになります。

この状態で、返信リンクでコメント欄がインラインで開くか、テストコメントが入れ子で表示されるかをテスト。大丈夫そうだったら、デフォルトテーマのstyle.cssを参考にしながら、コメント関係のスタイルを設定。

ただし、このままだと、コメント表示のフォーマットは変更する事ができません。デフォルトだと
xxx says:
日付/曜日/(編集リンク)
コメント
(返信リンク)
という並び。

これを変更するには、

<?php wp_list_comments(); ?>

というラインを

<?php wp_list_comments('callback=mytheme_comment'); ?>

というふうに変更し、自分のテーマフォルダ内のfunctions.phpファイルにmytheme_commentという関数を作成することになります。 (’mytheme_comment’は適宜変更。)

この関数の設定もいまひとつよくわからなかったので、このページにあるサンプルをがっつりコピーして、まずテスト。

function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <?php echo get_avatar($comment,$size='48',$default ); ?>
         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
      </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>
      <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
      <?php comment_text() ?>
      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>
<?php
        }

この状態だとデフォルトのテーマと同じように表示されるようなので、ここからすこしづつ、自分の表示したい順番、スタイルに変更していきました。←かなりのチカラ技です…

あと、以下のようにtypeを使えば、コメントとピンバックの表示方法を別に設定する事も可能だそうです。

<?php wp_list_comments('type=comment&callback=mytheme_comment'); ?>
<?php wp_list_comments('type=pingback&callback=mytheme_pingback'); ?>
TAG: 2.7 comment wordpress
CAT: wordpress | TIME: 3:28 PM
Tweet
  • [...] WP 2.7 のコメント返信機能を導入してみた。 [...]

    :: WordPress掲示板(ゲストブック)を設置してみました :: 2010-01-21 at 11.49 pm
    ( ✎ Reply )
Click here to cancel reply.

Spam Protection by WP-SpamFree



Prev/Next Posts

this week’s del.icio.us photos (2009-01-24)
ポラロイド・コラージュ

In Same Category

WordPress ビジネスブログ 標準ガイドブック
WP Plugin: WP-SpamFree

Recent Posts

  • サイトのお引越し
  • Posterous to WordPress
  • One Down.
  • February Resolution
  • DeliciousのブックマークをWordPressに移行する

Recent Comments

  • Franck C. on PB3: Questions, Feedbacks and Ideas
  • Kumitey on PB3: Questions, Feedbacks and Ideas
  • ganmo on PB3: Questions, Feedbacks and Ideas
  • Download and Installation « Photo-Biyori on PB2: How to Use Widgets in Photo-Biyori 2.0
  • Lindsay on PB3: Questions, Feedbacks and Ideas
  • Salih Deveci on PB3: Questions, Feedbacks and Ideas


Category

  • +doing+ Feed for all posts filed under +doing+ (49)
  • +feeling+thinking+ Feed for all posts filed under +feeling+thinking+ (26)
  • +listening+ Feed for all posts filed under +listening+ (5)
  • +reading+ Feed for all posts filed under +reading+ (9)
  • +watching+ Feed for all posts filed under +watching+ (41)
  • biboroku Feed for all posts filed under biboroku (11)
  • cameras Feed for all posts filed under cameras (31)
  • design+goods Feed for all posts filed under design+goods (31)
  • ebif Feed for all posts filed under ebif (10)
  • photography+art Feed for all posts filed under photography+art (16)
  • photography+me Feed for all posts filed under photography+me (40)
  • tsubuyaki Feed for all posts filed under tsubuyaki (58)
  • web+tech Feed for all posts filed under web+tech (20)
  • wordpress Feed for all posts filed under wordpress (34)
  • wp+photo-biyori Feed for all posts filed under wp+photo-biyori (13)

Search

Monthly Archives

  • 2011:
    01 02 03 04 05 06 07 08 09 10 11 12
  • 2010:
    01 02 03 04 05 06 07 08 09 10 11 12
  • 2009:
    01 02 03 04 05 06 07 08 09 10 11 12
  • 2008:
    01 02 03 04 05 06 07 08 09 10 11 12
  • 2007:
    01 02 03 04 05 06 07 08 09 10 11 12
  • 2006:
    01 02 03 04 05 06 07 08 09 10 11 12