- サイトデザイン工事中です。ご意見をお寄せください。
- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/register taxonomy
提供:WordPress Codex 日本語版
< 関数リファレンス
このページ「関数リファレンス/register taxonomy」は「引数」セクションが未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
この関数は分類を (カスタム分類として) 追加したり、上書きしたりします。分類名、影響を受けるオブジェクト名、パラメーターの配列を受け入れることができ、何も値を返しません。
分類名を選ぶ場合には他のカスタム分類や、WordPress の public/private クエリ変数と衝突しないように十分注意する必要があります。以下の予約語セクションでチェックしてください。
使い方
<?php register_taxonomy($taxonomy, $object_type, $args); ?>
パラメータ
- $taxonomy
- (文字列) (必須) 分類の名称。
- 初期値: なし
- $object_type
- (配列/文字列) (必須) 分類オブジェクトのオブジェクトタイプ。
- 初期値: なし
- $args
- (配列/文字列) (オプション) 引数の配列。
- 初期値: なし
引数
- label
- (文字列) (オプション) A plural descriptive name for the taxonomy marked for translation.
- 初期値: overridden by $labels->name
- labels
- (配列) (オプション) labels - An array of labels for this taxonomy. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
- 初期値: if empty, name is set to label value, and singular_name is set to name value
- 'name' - general name for the taxonomy, usually plural. The same as and overridden by $tax->label. Default is _x( 'Post Tags', 'taxonomy general name' ) or _x( 'Categories', 'taxonomy general name' ). When internationalizing this string, please use a gettext context matching your post type. Example:
_x('Writers', 'taxonomy general name'); - 'singular_name' - name for one object of this taxonomy. Default is _x( 'Post Tag', 'taxonomy singular name' ) or _x( 'Category', 'taxonomy singular name' ). When internationalizing this string, please use a gettext context matching your post type. Example:
_x('Writer', 'taxonomy singular name'); - 'search_items' - the search items text. Default is __( 'Search Tags' ) or __( 'Search Categories' )
- 'popular_items' - the popular items text. Default is __( 'Popular Tags' ) or null
- 'all_items' - the all items text. Default is __( 'All Tags' ) or __( 'All Categories' )
- 'parent_item' - the parent item text. This string is not used on non-hierarchical taxonomies such as post tags. Default is null or __( 'Parent Category' )
- 'parent_item_colon' - The same as
parent_item, but with colon:in the end null, __( 'Parent Category:' ) - 'edit_item' - the edit item text. Default is __( 'Edit Tag' ) or __( 'Edit Category' )
- 'update_item' - the update item text. Default is __( 'Update Tag' ) or __( 'Update Category' )
- 'add_new_item' - the add new item text. Default is __( 'Add New Tag' ) or __( 'Add New Category' )
- 'new_item_name' - the new item name text. Default is __( 'New Tag Name' ) or __( 'New Category Name' )
- 'separate_items_with_commas' - the separate item with commas text used in the taxonomy meta box. This string isn't used on hierarchical taxonomies. Default is __( 'Separate tags with commas' ), or null
- 'add_or_remove_items' - the add or remove items text and used in the meta box when JavaScript is disabled. This string isn't used on hierarchical taxonomies. Default is __( 'Add or remove tags' ) or null
- 'choose_from_most_used' - the choose from most used text used in the taxonomy meta box. This string isn't used on hierarchical taxonomies. Default is __( 'Choose from the most used tags' ) or null
- public
- (boolean) (オプション) Should this taxonomy be exposed in the admin UI.
- 初期値: true
- show_ui
- (boolean) (オプション) Whether to generate a default UI for managing this taxonomy.
- 初期値: if not set, defaults to value of public argument
- show_tagcloud
- (boolean) (オプション) Whether to show a tag cloud in the admin UI for this taxonomy
- 初期値: if not set, defaults to value of show_ui argument
- hierarchical
- (boolean) (オプション) Is this taxonomy hierarchical (have descendants) like categories or not hierarchical like tags.
- 初期値: false
- update_count_callback
- (文字列) (オプション) A function name that will be called to update the count of an associated $object_type, such as post, is pdated.
- 初期値: None
- rewrite
- (boolean または配列) (オプション) Set to false to prevent rewrite, or array to customize customize query var. Default will use $taxonomy as query var
- 初期値: true
- $args array
- 'slug' - prepend posts with this slug - defaults to taxonomy's name
- 'with_front' - allowing permalinks to be prepended with front base - defaults to true
- query_var
- (boolean) (オプション) False to prevent queries, or string to customize query var. Default will use $taxonomy as query var
- 初期値: $taxonomy
- capabilities
- (配列) (オプション) An array of the capabilities for this taxonomy.
- 初期値: なし
- 'manage_terms' - 'manage_categories'
- 'edit_terms' - 'manage_categories'
- 'delete_terms' - 'manage_categories'
- 'assign_terms' - 'edit_posts'
- _builtin
- (boolean) (非一般向け) Whether this taxonomy is a native or "built-in" taxonomy. Note: this Codex entry is for documentation - core developers recommend you don't use this when registering your own taxonomy
- 初期値: false
例
以下は "book" というカスタム投稿タイプに "genres (ジャンル)" と "writers (著者)" という分類を追加する例です。バージョン 3.0 以降のみの引数を使っています。
注: テーマの functions.php テンプレートファイル内でカスタム分類を定義できます。
<?php
// init アクションにフックして、そのタイミングで create_book_taxonomies を呼び出す
add_action( 'init', 'create_book_taxonomies', 0 );
// "book" カスタムタイプに対して genres と writers という2つの分類を作成する
function create_book_taxonomies()
{
// (カテゴリーのような) 階層化できる新規分類を追加
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
);
register_taxonomy('genre',array('book'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
));
// (タグのような) 階層化できない新規分類を追加
$labels = array(
'name' => _x( 'Writers', 'taxonomy general name' ),
'singular_name' => _x( 'Writer', 'taxonomy singular name' ),
'search_items' => __( 'Search Writers' ),
'popular_items' => __( 'Popular Writers' ),
'all_items' => __( 'All Writers' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Writer' ),
'update_item' => __( 'Update Writer' ),
'add_new_item' => __( 'Add New Writer' ),
'new_item_name' => __( 'New Writer Name' ),
'separate_items_with_commas' => __( 'Separate writers with commas' ),
'add_or_remove_items' => __( 'Add or remove writers' ),
'choose_from_most_used' => __( 'Choose from the most used writers' )
);
register_taxonomy('writer','book',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'writer' ),
));
}
?>
予約語
- p
- posts
- w
- cat
- withcomments
- withoutcomments
- s
- search
- exact
- sentence
- debug
- calendar
- page
- paged
- more
- tb
- pb
- author
- order
- orderby
- year
- monthnum
- day
- hour
- minute
- second
- name
- category_name
- tag
- feed
- author_name
- static
- pagename
- page_id
- error
- comments_popup
- attachment
- attachment_id
- subpost
- subpost_id
- preview
- robots
- taxonomy
- term
- cpage
- post_type
- offset
- posts_per_page
- posts_per_archive_page
- showposts
- nopaging
- post_type
- post_status
- category__in
- category__not_in
- category__and
- tag__in
- tag__not_in
- tag__and
- tag_slug__in
- tag_slug__and
- tag_id
- post_mime_type
- perm
- comments_per_page
変更履歴
Since: 2.3
ソースファイル
register_taxonomy() は wp-includes/taxonomy.php にあります。
最新英語版: WordPress Codex » Function Reference/register_taxonomy (最新版との差分)