functions.php設定, カスタム分類, カスタム投稿タイプ
0

カスタム投稿タイプとカスタム分類をプラグイン無で設定,表示

この記事もまだ、途中です….

同じような記事を何度か書いているが、
WordPress初心者の自分なりに試行錯誤した結果、PHPの勉強にもなるし基本はなるべくプラグインに頼らない!にこだわっていくことに決定。(挫折しそうですが…)
なので、
「カスタム投稿タイプ」と「カスタム分類」の自分なりのまとめ的なメモ。

まず、
946696 WordPressのテーマ内functions.phpが長くなりがちなので、functionsフォルダにファイルを分割して置くとき書いとくと便利 – gistlogを参考にして、
/wp-content/themes/適用しているテーマのフォルダ/
に、「functions」というフォルダを作り、
この中に「custom-post-taxonomy.php」を作成。
これを「カスタム投稿タイプ」「カスタム分類」に関する設定を記述する専用ファイルとした上で、functions.phpで読み込ませる為に下記をfunctions.phpに記述。

/*
 * functionsフォルダにあるファイルをすべて読み込む
 */
foreach(glob(TEMPLATEPATH."/functions/*.php") as $file){
	require_once $file;
}

※なるほど!こんな方法があったんですね。どんどん長く解りにづらくなってしまうfunctions.phpへの追加記述もこれならスッキリ!!

そして、
yusk -ユースク- | always as a designer様のカスタム投稿タイプとカスタムタクソノミーをプラグインを使わずに実現するという記事を参考にさせて頂いております。
かちびと.net様のWordPressのカスタム投稿(ポスト)タイプを作成するまでの手順リスト – かちびと. net
を、参考にさせて頂き「カスタム投稿タイプ」「カスタム分類」専用の/functions/custom-post-taxonomy.phpへ下記を記述。

<?php
// カスタム投稿タイプを作成
// 店舗投稿タイプ
function night_custom_post_type()
{

$labels = array(
'name' => _x('店舗情報', 'post type general name'),
'singular_name' => _x('店舗情報', 'post type singular name'),
'add_new' => _x('店舗情報を追加', 'night'),
'add_new_item' => __('新しい店舗情報を追加'),
'edit_item' => __('店舗情報を編集'),
'new_item' => __('新しい店舗情報'),
'view_item' => __('店舗情報を編集'),
'search_items' => __('店舗情報を探す'),
'not_found' => __('店舗情報はありません'),
'not_found_in_trash' => __('ゴミ箱に店舗情報はありません'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 2,
'has_archive' => true,
'supports' => array('title','editor', 'custom-fields','author','excerpt','comments'),
'taxonomies' => array('type','tokyo','nishi_tokyo','popkey')
);
register_post_type('night',$args);

// カスタム分類を作成

//タイプ
$args = array(
'label' => 'タイプ',
'public' => true,
'show_ui' => true,
'hierarchical' => true
);
register_taxonomy('type','night',$args);

//東京23区
$args = array(
'label' => 'エリア東京',
'public' => true,
'show_ui' => true,
'hierarchical' => true
);
register_taxonomy('tokyo','night',$args);

//西東京
$args = array(
'label' => 'エリア西東京',
'public' => true,
'show_ui' => true,
'hierarchical' => true
);
register_taxonomy('nishi_tokyo','night',$args);

//タグタイプ
$args = array(
'label' => '注目キーワード',
'public' => true,
'show_ui' => true,
'hierarchical' => false
);
register_taxonomy('popkey','night',$args);
}

add_action('init', 'night_custom_post_type');
?>

~~~~~
【カスタム投稿タイプに権限を】
The blog of H.Fujimoto様の
WordPress 3.0のカスタム投稿タイプ機能(その2) – The blog of H.Fujimoto内、
「2-8.capability_type」に記載してある!

【カスタム分類に権限を】
The blog of H.Fujimoto様の
register_taxonomy関数の書き方 – The blog of H.Fujimoto内、
「2-9.capabilities」に軽く記載してある!

The blog of H.Fujimoto様にはMTを使っているころより、このブログ&書籍などお世話になりまくりです。

関連記事
デフォルト投稿postの本文フィールドを非表示にする
カテゴリーページ(アーカイブ)で複数ループ
カスタム投稿タイプをプラグイン無しで設定,表示