投稿記事一覧に新たに項目を追加したい
-
閲覧ありがとうございます。初心者です。
商品一覧ページを作る為に、「shop menu]というプラグインを使っています。
こちらのプラグインは、通常の記事投稿ページとは別に、商品投稿ページにて商品ページを
管理できるようになっています。通常の投稿一覧の管理画面では、記事一つ一つにタイトル、カテゴリー、タグ、日付などの表示がありますが、
プラグインを使用した商品投稿ページでは、ページタイトルと商品カテゴリ、日付しか表示項目がありません。
(表示オプションでもタイトル、日付のみになっています)投稿一覧ページと同じように、タグの表示項目を追加し、またタグを記事につけられるようにしたいのですが
どうしたらいいでしょうか。プラグインのphpファイルをいじればいいのかなと思いますが、どのように記述すればよいかわかりません。
気になる部分を記載しますregister_post_type( 'shop_menu', $menu_setting); $category = array( 'label' => '商品カテゴリ', 'public' => true, 'show_ui' => true, 'hierarchical' => true, ); register_taxonomy( 'menu_type', 'shop_menu', $category); } function manage_posts_columns($columns) { $columns['shop_category'] = "商品カテゴリー"; unset( $columns['date'] ); $columns['date'] = '日時'; $colums['shop_tags'] = "商品タグ"; unset( $colums['tags'] ); return $columns; function add_shop_category_column($column_name, $post_id){ if( $column_name == 'shop_category' ){ $category = get_the_term_list($post_id, 'menu_type'); } if ( isset($category) && $category ){ echo $category; }else{ echo __('None'); } }
-
コードからすると、shop_menu というカスタム投稿タイプを登録して管理を行っているようなので、この shop_menu というカスタム投稿タイプに対して、別途カスタム分類の登録を行えば実現できるかと思います。
カスタム分類の登録は、register_taxonomy を用い、一覧にタグを表示するには、引数の show_admin_column を true として設定する必要があります。
このカスタム分類の登録は、プラグインのファイルを編集せずに、テーマのfunctions.php に記述することでも対応が可能です。
回答ありがとうございます。
試行錯誤しながらいじってみたところ、項目のところに「タグ」を表示することはできましたが、編集ページやメニューの部分にタグの編集ページがでてきません。
register_taxonomyを挿入しようとすると、コードが間違っているためかエラーになってしまいます。
どのように記述すればよいでしょうか。お願いします。function register_shop_menu(){ $labels = array( 'menu_name' => 'ShopMenu', 'all_items' => '商品一覧', 'name' => '商品一覧', 'add_new_item' => '商品を追加', 'edit_item' => '商品を編集', ); $supports = array('title', 'editor', 'thumbnail', 'revisions', 'page-attributes', 'slug'); $menu_setting = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'page', 'hierarchical' => false, 'menu_position' => null, 'supports' => $supports, 'has_archive' => true, ); register_post_type( 'shop_menu', $menu_setting); $category = array( 'label' => '商品カテゴリ', 'public' => true, 'show_ui' => true, 'hierarchical' => true, ); register_taxonomy( 'menu_type', 'shop_menu', $category); /*追記部分*/ register_post_type( 'shop_menu' , $menu_setting); $args = array( 'label' => 'タグ', 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'hierarchical' => false, ); /*追記部分終わり*/ } function manage_posts_columns($columns) { $columns['shop_category'] = "商品カテゴリー"; unset( $columns['date'] ); /*追記部分*/ $columns['tags'] = "タグ"; /*追記部分終わり*/ $columns['date'] = '日時'; return $columns; } function manage_menu_type_columns($columns) { $columns['menu_shortcode'] = "ショートコード"; unset( $columns['description'] ); return $columns; } function add_shop_category_column($column_name, $post_id){ if( $column_name == 'shop_category' ){ $category = get_the_term_list($post_id, 'menu_type'); } if ( isset($category) && $category ){ echo $category; }else{ echo __('None'); }
すみません。見直し+訂正を加えてなんとかできるようになりました。
タグとカテゴリーは通常の記事とあえて共通にしています。function on_init() { $this->init_custom_metabox(); $this->register_shop_menu(); } function register_shop_menu(){ $labels = array( 'menu_name' => 'ShopMenu', 'all_items' => '商品一覧', 'name' => '商品一覧', 'add_new_item' => '商品を追加', 'edit_item' => '商品を編集', ); $supports = array('title', 'editor', 'thumbnail', 'revisions', 'page-attributes', 'slug'); $menu_setting = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'page', 'hierarchical' => false, 'menu_position' => null, 'supports' => $supports, 'has_archive' => true, ); register_post_type( 'shop_menu', $menu_setting); $category = array( 'label' => '商品カテゴリ', 'public' => true, 'show_ui' => true, 'hierarchical' => true, ); register_taxonomy( 'category', 'shop_menu', $category); register_post_type( 'shop_menu' , $menu_setting); $args = array( 'label' => 'タグ', 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'hierarchical' => false, ); register_taxonomy( 'post_tag', 'shop_menu', $post_tag); } function manage_posts_columns($columns) { $columns['shop_category'] = "商品カテゴリー"; unset( $columns['date'] ); $columns['tags'] = "タグ"; $columns['date'] = '日時'; return $columns; } function manage_menu_type_columns($columns) { $columns['menu_shortcode'] = "ショートコード"; unset( $columns['description'] ); return $columns; } function add_shop_category_column($column_name, $post_id){ if( $column_name == 'shop_category' ){ $category = get_the_term_list($post_id, 'category'); } if ( isset($category) && $category ){ echo $category; }else{ echo __('None'); }
- トピック「投稿記事一覧に新たに項目を追加したい」には新たに返信することはできません。