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

问题描述 投票:0回答:1

在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' );
wordpress custom-post-type
1个回答
-2
投票

请将CPT中的“menu_position”设置为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'),
  );
© www.soinside.com 2019 - 2024. All rights reserved.