post_class

Sponsored Link

WordPress2.7はシンプルなスタイリングを実行するテーマ作家に役立つ記事クラスのための新しい機能が含まれます。関数は、適切に十分な、post_class()と呼ばれます。

Sponsored Link

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

テーマにこの関数を使用するには、単純にループに理にかなっている場所に追加されます。ほとんどのテーマは、いくつかに分類されたDIV内の全ての記事をカプセル化します。そのDIVは、通常のclass=”post”のようなものと似ています。そのクラスの代わりに、ただのpost_classの代わりに呼び出して追加します。このように:

To use this function in a theme, you will simply add it to the Loop in a place that makes sense. Most themes encapsulate every post within a DIV of some sort. That DIV usually has a class=”post” or something similar. Instead of that class, just add a call to post_class instead. Like so:

<div id="post-<?php the_ID(); ?>"<?php post_class(); ?>>

post_class()はdivの場所にclass=”whatever”を出力します。この値は、いくつかの異なるクラスを含みます:post-123(数値post ID)、記事、ページ、添付ファイル(投稿タイプ)は、hentry(Atomのmicroformatのページ)、category-X(ここでのXは、すべての投稿に含まれるカテゴリー記事のスラッグです)、そしてtag-X(シンプルですが、タグ付け)。また、付箋記事としてマークした投稿に”付箋”を追加します。これらは様々な方法でテーマの部分別にスタイルを簡単に作成します。

The post_class() outputs the class=”whatever” piece for that div. This includes several different classes of value: post-123 (the numerical post ID), post or page or attachment (the post type), hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds “sticky” for posts marked as sticky posts. These make it easy to style different parts of the theme in different ways.

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

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

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

これはクラスのリストに”special”が追加されるでしょう。
あなたのコードが複雑であり、それがより便利な場合、クラスのリストで区切られたスペースか、それとも1つのクラスごとに文字列を与える事が出来ます。クラスを追加すると、Wordpressは重複のチェックをしません。

This will add “special” to the class list. You can either give it a space separated list of classes, or an array of strings with one class each, if your code is more complex and that is more useful. When adding additional classes, WordPress does not check for duplicates.

代替ループ内またはループ外で記事を表示するために、post_class関数への2番目のパラメータではpost IDにすることができます。クラスは、その投稿から決定されます。

For displaying posts outside the Loop or in an alternate Loop, the second parameter to the post_class function can be the post ID. Classes will then be determined from that post.

<?php post_class('',$post_id); ?>

CSSスタイリングのためのフックとして使用できる次のクラスを追加することができます:

It can add the following classes which you can use as a hook for CSS-styling:

  • .post-id
  • .post (or .page or .attachment, depending on the post type)
  • .sticky
  • .hentry
  • .category-misc
  • .category-example
  • .tag-news
  • .tag-wordpress
  • .tag-markup

参照

Template_Tags/comment_class

このページは、不完全としてマークされます。あなたはそれを拡大しCodexを助けることができます。

This page is marked as incomplete. You can help Codex by expanding it.

Sponsored Link