the_category

Sponsored Link

カテゴリーまたは記事に属するカテゴリーのリンクを表示します。このタグはループ内で使用する必要があります。

Sponsored Link

Displays a link to the category or categories a post belongs to. This tag must be used within The Loop.

the_categoryのテンプレートタグ使用方法

<?php the_category( $separator, $parents, $post_id ); ?> 

the_categoryのパラメーター

タグパラメータに渡す方法:PHPの関数スタイルのパラメータを持つタグ

How to Pass Tag Parameters: Tags with PHP function-style parameters

separator

(string) テキストまたは文字列は、各カテゴリーのリンクの間に表示されます。デフォルトでは、順不同リスト内にリンクが配置されます。

(string) Text or character to display between each category link. The default is to place the links in an unordered list.

parents

(string) 子(サブ)カテゴリーの存在をリンクをどのように表示するか。オプションがあります:

(string) How to display links that reside in child (sub) categories. Options are:

  • ‘multiple’ – リンクテキストの”parent/child”という関係を示すと、親と子カテゴリーにリンクを分けて表示します。
  • ‘single’ – リンクテキストの”parent/child”という関係を示すと、子カテゴリーのリンクのみ表示します。
  • ‘multiple’ – Display separate links to parent and child categories, exhibiting “parent/child” relationship.
  • ‘single’ – Display link to child category only, with link text exhibiting “parent/child” relationship.

注:デフォルトでは、子カテゴリーへのリンクは、何の関係も提示しません。

Note: Default is a link to the child category, with no relationship exhibited.

post_id

(Integer)Post IDでカテゴリーを取得します。デフォルト値はfalse(現在の投稿)です。

(Integer) Post ID to retrieve categories. The default value is false (the current post).

スペースで区切る方法

スペースを区切りとしてカテゴリーリストに使います。

This usage lists categories with a space as the separator.

<p>Categories:<?php the_category(' '); ?></p>

カンマで区切る方法

コンマ(複数の場合)によって区切られた各カテゴリーを、カテゴリーへのリンクを表示します。

Displays links to categories, each category separated by a comma (if more than one).

<p>This post is in:<?php the_category(', '); ?></p>
This post is in: WordPress, Computers, Blogging

矢印で区切る方法

矢印(>)で区切られたカテゴリーを、カテゴリーのリンクとして表示します。 (注:一部の視聴者は、サブカテゴリーのその前のとして、>の次のカテゴリーを解釈することがありますので、これを使用する時は注意してください。)

Displays links to categories with an arrow (>) separating the categories. (Note: Take care when using this, since some viewers may interpret a category following a > as a subcategory of the one preceding it.)

<p>Categories:<?php the_category(' &amp;gt; '); ?></p>
Categories: WordPress > Computers > Blogging

中黒点によって区切る方法

中黒点(•)で区切られたカテゴリーのカテゴリーリンクを表示します。

Displays links to categories with a bullet (•) separating the categories.

<p>Post Categories:<?php the_category(' &amp;bull; '); ?></p>
Post Categories: WordPressComputersBlogging

ソースファイル

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

  • the_category() is located in wp-includes/category-template.php

変更ログ

  • 2.5 : Added the post_id parameter.

関連テンプレートタグ

the_category, the_category_rss, single_cat_title, category_description, wp_dropdown_categories, wp_list_categories, get_the_category, get_category_parents, get_category_link, is_category, in_category

Sponsored Link