[wordpress]カスタム投稿タイプのコード
個人で作ってたテーマの中に何故か無かったのでついでに覚書
○○○部分を変更すればOK
<?php /* Add Custom Type ------------------------------------------*/ add_action('init', 'add_○○○_post_type'); function add_○○○_post_type() { $params = array( 'labels' => array( 'name' => 'カスタム投稿タイプ', 'singular_name' => '取扱店舗', 'add_new' => '新規追加', 'add_new_item' => '記事を新規追加', 'edit_item' => '記事を編集する', 'new_item' => '新規記事', 'all_items' => '記事一覧', 'view_item' => '記事の説明を見る', 'search_items' => '検索する', 'not_found' => '記事が見つかりませんでした。', 'not_found_in_trash' => 'ゴミ箱内に記事が見つかりませんでした。' ), 'public' => true, 'has_archive' => true, 'supports' => array( 'title', 'editor', 'author', 'custom-fields', ), 'taxonomies' => array('○○○_category','○○○_tag') ); register_post_type('○○○', $params); } add_action('init', 'create_○○○_taxonomies'); function create_○○○_taxonomies() { // カテゴリを作成 $labels = array( 'name' => 'カテゴリ', 'singular_name' => 'カテゴリ', 'search_items' => 'カテゴリを検索', 'all_items' => '全てのカテゴリ', 'parent_item' => '親カテゴリ', 'parent_item_colon' => '親カテゴリ:', 'edit_item' => 'カテゴリを編集', 'update_item' => 'カテゴリを更新', 'add_new_item' => '新規カテゴリを追加', 'new_item_name' => '新規カテゴリ', 'menu_name' => 'カテゴリ' ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'rewrite' => array( 'slug' => '○○○_cat' ) ); register_taxonomy( '○○○_category', '○○○', $args ); // タグを作成 $labels = array( 'name' => 'タグ', 'singular_name' => 'タグ', 'search_items' => 'タグを検索', 'all_items' => 'タグ', 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => 'タグを編集', 'update_item' => 'タグを更新', 'add_new_item' => '新規タグを追加', 'new_item_name' => '新規タグ', 'separate_items_with_commas' => 'タグをコンマで区切る', 'add_or_remove_items' => 'タグを追加or削除する', 'choose_from_most_used' => 'よく使われているタグから選択', 'not_found' => 'アイテムは見つかりませんでした', 'menu_name' => 'タグ' ); $args = array( 'hierarchical' => false, 'labels' => $labels, 'update_count_callback' => '_update_post_term_count', 'rewrite' => array( 'slug' => '○○○_tag' ) ); register_taxonomy( '○○○_tag', '○○○', $args ); } ?>