コメント関係

パラメータの設定や、項目の増やし方等
まとめ
single.phpにcomment_template();を挿入
そうするとcomments.phpが呼ばれる
comments.phpの中でコメント表示が行なわれ、さらにcomment_form($args)で入力フォームが呼ばれる
$argsには沢山のパラメータがあり、好みでカスタマイズできる

<?php $defaults = array(
	'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
	'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
	'must_log_in'          => '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
	'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
	'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
	'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
	'id_form'              => 'commentform',
	'id_submit'            => 'submit',
	'title_reply'          => __( 'Leave a Reply' ),
	'title_reply_to'       => __( 'Leave a Reply to %s' ),
	'cancel_reply_link'    => __( 'Cancel reply' ),
	'label_submit'         => __( 'Post Comment' ),
);
?>

徹底的にカスタマイズしたい時はフック等を活用
• comment_form_before
• comment_form_must_log_in_after
• comment_form_top
• comment_form_logged_in_after
• comment_notes_before
• comment_form_before_fields
• comment_form_field_{$name} (a filter on each and every field, where {$name} is the key name of the field in the array)
• comment_form_after_fields
• comment_form_field_comment (a filter on the “comment_field” default setting, which contains the textarea for the comment)
• comment_form (action hook after the textarea, mainly for backward compatibility)
• comment_form_after
• comment_form_comments_closed

コメントリストの方だが、階層型にするためにはtwenty-tenか何かのcomments.phpを使って、function内にある
twentyten_comment( $comment, $args, $depth )
関数を引っ張って来る必要があった。

とにかく、コメントリストのカスタマイズをしたい時は、twentyten_comment( $comment, $args, $depth )
をいじれば良いという事だ。
というか、comments.php内の
wp_list_comments( array( ‘callback’ => ‘myComment’ ) );
とともに、myComment()を自作する。その雛形は2010や2011の関数を使うといいだろう。

要は
・リスト
comments_template() -> comments.php / wp_list_comments -> myComment()
・フォーム
comments_template() -> comments.php / comment_form($args)

結構複雑なのだ。

コメント

タイトルとURLをコピーしました