将自定义帖子类型添加到子菜单项

时间:2017-09-21 14:49:01

标签: wordpress custom-post-type

在wordpress管理菜单中,

我想在子菜单项中添加自定义帖子类型。例如, Menu Item -> Submenu Item -> Custom Post Type

我认为我很接近,但可能有一种更简单的方法来实现这一目标。或者有办法实现这一目标吗?我想到的另一个选择是为所有子项目提供类别。寻找关于如何以及我应该做什么的一些建议。

目前有以下内容:

function.php

菜单项

function admin_menu_experience() {

     add_menu_page(
         'Experience',
         'Experience',
         'read',
         'test',
         '',
         'dashicons-admin-users',
         40
     );

  }

  add_action( 'admin_menu', 'admin_menu_experience' );

子菜单项

function admin_submenu_additional_self_test(){
add_submenu_page(
  'test',
  'Test',
  'Test',
  'read',
  'test',
  '',
  'dashicons-admin-users',
  40
);
}
add_action( 'admin_menu', 'admin_submenu_additional_self_test' );

自定义帖子类型

function register_subitem_test() {
  $args = array (
    'labels' => array (
      'name' => __( 'Healthcare', 'healthcare' ),
      'singular_name' => __( 'Healthcare', 'healthcare' ),
    ),
    'description' => 'View Available Properties',
    'supports' => array( 'title' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => 'test',
    // 'taxonomies' => array('category'),
    'rewrite' => array('slug' => 'healthcare' ),
    'supports' => array('title', 'editor', 'revisions', 'thumbnail'),
  );
  register_post_type( 'healthcare', $args );
 }
 add_action( 'init', 'register_subitem_test' );

1 个答案:

答案 0 :(得分:-2)

请设置' menu_position'在CPT到9,它将工作

// Custom Post Type
function register_subitem_test() {
  $args = array (
    'labels' => array (
      'name' => __( 'Healthcare', 'healthcare' ),
      'singular_name' => __( 'Healthcare', 'healthcare' ),
    ),
    'description' => 'View Available Properties',
    'supports' => array( 'title' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => 'test',
    // 'taxonomies' => array('category'),
    'rewrite' => array('slug' => 'healthcare' ),
    'menu_position'      => 9,
    'supports' => array('title', 'editor', 'revisions', 'thumbnail'),
  );