wp カスタム投稿を作成その2
2013.11.27
                    スタッフブログ
                  
どもー、タカミチです。
今回は前回の続きというか、
書き忘れたことがあったので、その話です。
前回はカスタム投稿タイプを作成するでしたが
今回は作成した投稿タイプを分類わけする方法をメモ
まず、WordPressでは、カテゴリー分け、分類のことををカスタムタクソノミーというらしい。
・・・難解な言葉だ
まあ分類ってことだろう。
んで分類分けの方法は、前回のfunction.php
add_action( ‘init’, ‘create_post_type’ );
function create_post_type() {
register_post_type( ‘store’, /* post-type */
array(
‘labels’ => array(
‘name’ => __( ‘お店’ ),
‘singular_name’ => __( ‘お店’ )
),
‘public’ => true,
‘menu_position’ =>5,
)
);
}
function create_post_type() {
register_post_type( ‘store’, /* post-type */
array(
‘labels’ => array(
‘name’ => __( ‘お店’ ),
‘singular_name’ => __( ‘お店’ )
),
‘public’ => true,
‘menu_position’ =>5,
)
);
}
のコードに追加↓
add_action( ‘init’, ‘create_post_type’ );
function create_post_type() {
register_post_type( ‘books’, /* post-type */
array(
‘labels’ => array(
‘name’ => __( ‘本’ ),
‘singular_name’ => __( ‘本’ )
),
‘public’ => true,
‘menu_position’ => 5,
)
);
function create_post_type() {
register_post_type( ‘books’, /* post-type */
array(
‘labels’ => array(
‘name’ => __( ‘本’ ),
‘singular_name’ => __( ‘本’ )
),
‘public’ => true,
‘menu_position’ => 5,
)
);
/*↓ ここから ↓*/
  register_taxonomy(
    ‘stores’, /* タクソノミーの名前 */
    ‘store’, /* store投稿で設定する */
    array(
      ‘hierarchical’ => true, /* 親子関係が必要なければ false */
      ‘update_count_callback’ => ‘_update_post_term_count’,
      ‘label’ => ‘店のカテゴリー’,
      ‘singular_label’ => ‘店のカテゴリー’,
      ‘public’ => true,
      ‘show_ui’ => true
    )
  );
/*↑ ここまで ↑*/
}
これでお店のメニューに店のカテゴリーというのが追加されます。
なるほど、これでどんどんカスタム投稿が区分わけできるのですね。
