這個用法通常會跟 register_post_type 一起用,當我們自定一個新的文章類型時,如果需要有分類功能,就必須另外寫一個 register_taxonomy 放上去使用。簡單的語法如下:

function create_custom_tax() {
register_taxonomy(
    'mypost', //分類法別名
    'mypost', //對應的文章類型
    array(
      'label' => '我的分類',
'labels' => array(), //請查閱官方參數說明
'public' => true,
      'hierarchical' => true, //是否按多層次分類
    )
);
add_action( 'init', 'create_custom_tax' );


補充說明:
register_taxonomy 和 register_post_type 中的 labels 參數非常相近,可以設定的項目很多,大家可以上官網自行查閱一下。
http://codex.wordpress.org/Function_Reference/register_taxonomy

參考網站:
http://www.wphub.com/wordpress-custom-post-type/

One Comment

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *