comment_class

Sponsored Link

WordPressは、単独のスタイルを提供するテーマ著作者を手助けするために、コメントのクラスのために新しい関数をインクルードします。関数は、適切で十分な、comment_class()を呼び出します。

より詳細はpost_class()を参照してください。

Sponsored Link

WordPress includes a new function for comment classes, which will help theme authors perform simpler styling. The function is, appropriately enough, called comment_class().

See also post_class() for more details.

<li<?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">

comment_class()はdivの場所にclass=”whatever”を出力します。いくつかの異なるクラスの値をインクルードします:comment, even (or odd), thread-even, depth-1,等。これらはさまざまな方法でテーマの異なる部分のスタイルを簡単に作ります。

The comment_class() outputs the class=”whatever” piece for that div. This includes several different classes of value: comment, even (or odd), thread-even, depth-1, etc.. These make it easy to style different parts of the theme in different ways.

具体的には、次の条件に基づいて以下のクラスに適用されます:

Specifically, it will apply the following classes, based on the following conditions:

  • comment_type:通常のコメントは、”comment”クラスが追加されます。他の全てのタイプの為に、クラスとしてcomment_typeの値を追加します。
  • user_id:コメントが登録ユーザーによって作られた場合、”byuser”と”comment-author-” + user_nicenameの部分が削除された(つまり削除スペース)クラスを追加します。また、コメントが記事の著作者のオリジナルによって、”bypostauthor”クラスが追加された場合です。
  • Odd/Even:コメント数が偶数の場合、”even”クラスを追加します。それ以外の場合、”alt” と “odd”クラスを追加します。
  • Comment Depth:クラスの”depth=” + コメントの深さが常に追加されます。
  • Top-level Comments:コメントの深さがトップレベル(1)の場合、コメント数が偶数か奇数かどうか次第で”thread-even” と”thread-alt” と “thread-odd”を追加します。
  • オプションクラスのパラメーターがcomment_class()に引き継がれる場合、そのクラスは他の全てに追加されます。これは独自のカスタムコメントクラスを定義しています。
  • comment_type: for normal comments, adds class “comment”. For all other types, it adds the value of the comment_type as the class
  • user_id: if the comment was made by a registered user, then adds class “byuser” and “comment-author-” + the user_nicename sanitized (i.e. spaces removed). Also, if the comment is by the original author of the post, the class “bypostauthor” is added.
  • Odd/Even: if the comment number is even, adds class “even”. Otherwise, adds class “alt” and “odd”.
  • Comment Depth: The class “depth=” + the comment depth is always added
  • Top-level Comments: If comment depth is top level (1), then adds “thread-even” or “thread-alt” and “thread-odd” depending on whether the comment number is even or odd.
  • If the optional class parameter is passed to comment_class(), then that class gets added to all the others. This is useful for defining your own custom comment class.

独自のクラスを追加したい特殊なケースについては、post_classでもサポートしています:

For special cases where you want to add your own classes, post_class supports that too:

<?php comment_class('special'); ?>

これは、”特別な”クラスのリストを追加するでしょう。

また、comment_class()は次のグローバル変数を使用する場合は注意してください。それらの変数は、出力をもたらすcomment_class()を呼び出す前に設定する事ができます: global $comment_alt, $comment_depth, $comment_thread_alt;

例えば、あなたがいつも最初のコメントが規則正しくなるようにスタートしたい場合、$comment_alt=FALSEと強制する事が出来ます。
comment_class()関数は、あなたの為にこの変数を代替するでしょう。

This will add “special” to the class list.

Also note that comment_class() uses the following global variables. So these variables can be set prior to calling comment_class() to effect the output: global $comment_alt, $comment_depth, $comment_thread_alt;

For example, you can force $comment_alt=FALSE if you always want to start with the first comment being even. The comment_class() function will then alternate this variable for you.

ソースファイル

comment_class()は、wp-includes/comment-template.php内に位置しています。

comment_class() is located in wp-includes/comment-template.php.

参照

  • Template_Tags/post_class
Sponsored Link