megane9988
8/8/2013 - 7:13 AM

カスタム投稿タイプとカスタムタクソノミーを新たに追加するプラグイン

カスタム投稿タイプとカスタムタクソノミーを新たに追加するプラグイン

<?php
/**
 * @package meganecustom
 * @version 0.0.1
 */
/*
Plugin Name: meganecustom
Plugin URI: http://m-g-n.me/
Description: カスタム投稿タイプを作る
Author: megane9988
Version: 0.0.1
Author URI: http://m-g-n.me
*/
// カスタム投稿タイプを登録 -------------------------------------------
function create_post_type_meganecustom() {
    $labels = array(
        'name'                => 'メガネ',
        'all_items'           => 'メガネの一覧',
    );
    $args = array(
        'labels'              => $labels,
        'supports'            => array('title','editor','excerpt','thumbnail'),
        'public'              => true,       // 公開するかどうが
        'show_ui'             => true,       // メニューに表示するかどうか
        'menu_position'       => 5,          // メニューの表示位置
        'has_archive'         => true,       // アーカイブページの作成
        'menu_icon'           => get_bloginfo('template_url').'/assets/img/icon-meganecustom.png',
    );
    register_post_type( 'meganecustom', $args );
}
add_action( 'init', 'create_post_type_meganecustom', 0 );

// カスタムタクソノミーを登録 -------------------------------------------
function create_custom_taxonomy_megane_custom() {
    register_taxonomy(
        'megane-cat',  // カスタム分類名
        'meganecustom',      // カスタム分類を使用する投稿タイプ名
        array(
            'hierarchical' => true,
            'label' => 'メガネカテゴリー',
            'singular_label' => 'メガネカテゴリー',
            'public' => true,
            'show_ui' => true,
        )
    );
}
add_action( 'init', 'create_custom_taxonomy_megane_custom', 0 );
?>