コメントの本文に返信件数を追加
コメント欄のツリー表示を解除した際に、コメントに対する返信件数が一目でわかるようにコメント本文に表示を追加してみました。

子供のコメントを取得して返信件数を追加する
comment_textフィルターフックで子供のコメントを取得して件数表示を追加します。
// コメント本文の下に返信件数を追加
function custom_comment_text_reply_count($comment_text, $comment = null) {
if($comment == null)
{
return $comment_text;
}
// コメントの返信(子コメント)を取得
$children = $comment->get_children();
$cnt = count($children);
if($cnt > 0)
{
// 返信があれば件数表示をテキストに追加
$rep_count_text = '<div class="rep-count"><i class="fa fa-comment"></i>'.$cnt.'件の返信</div>';
$comment_text = $comment_text .$rep_count_text;
}
return $comment_text;
}
// いいねプラグインのpriority(200)の前に設定
add_filter('comment_text', 'custom_comment_text_reply_count', 190, 2);
他のプラグインでコメント本文中に表示しているものがある場合、表示の順序によって priority の設定に注意が必要です。
コメント