LoginSignup
0
0

More than 5 years have passed since last update.

カスタム投稿タイプを登録する

Posted at

新しい投稿記事用に、カスタム投稿タイプを登録します

1. functions.phpに登録します

  • 登録したいカスタム投稿タイプをfunctions.phpに追加します
//カスタム投稿タイプ
function create_post_type() {
  register_post_type(
    'newtype', //投稿タイプ名
    array(
      'label' => '新しいタイプの投稿',
      'labels' => array(
         'all_items' => '新しいタイプの投稿一覧',
         ),
      'description' => '新しいタイプの投稿の紹介です',
      'public' => true,
      ‘menu_position’ =>5,    
      'has_archive' => true,
      'supports' => array( 
        'title',
        'editor',
        'author',
        'custom-fields',
      ),
    )
  );
}
add_action( 'init', 'create_post_type' );

2. 対応する投稿ページを用意します

  • single.phpをコピーして、single-カスタム投稿名.php(上記の例では"single-newtype.php")を用意します

スクリーンショット 2018-11-20 17.18.19.png

3. 管理画面から確認します

  • 管理画面に新しいメニューが登録され、新たに用意したsingle-カスタム投稿名.phpで新規の投稿が可能になっていることを確認します。

スクリーンショット 2018-11-20 17.19.40.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0