我有一个带有一组菜单的自定义插件。我也有一个自定义帖子类型,但我不知道如何将自定义帖子推到插件的管理菜单项下。
自定义贴子的代码和分类如下所示:
function mmd_list_admin_manualentry() {
$labels = array(
\'name\' => _x( \'Manage Lists\', \'mmd_list\' ),
\'singular_name\' => _x( \'Manage List\', \'mmd_lists\' ),
\'add_new\' => _x( \'New List\', \'mmd_list\' ),
\'add_new_item\' => __( \'Add New List\' ),
\'edit_item\' => __( \'Edit List\' ),
\'new_item\' => __( \'New List\' ),
\'all_items\' => __( \'Manage Lists\' ),
\'view_item\' => __( \'View List\' ),
\'search_items\' => __( \'Search List\' ),
\'not_found\' => __( \'No Listing found\' ),
\'not_found_in_trash\' => __( \'No Listings found in the Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'CUSTOM POST TEST\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'This post type holds all posts for your directory items.\',
\'public\' => true,
\'menu_position\' => 10,
\'show_ui\' => true,
\'show_in_menu\' => \'mmd_list_options\', // Use the plugin menu slug
\'supports\' => array( \'title\' ),
\'has_archive\' => true,
);
register_post_type( \'mmd_list\', $args );
}
add_action( \'init\', \'mmd_list_admin_manualentry\', 0 );
function mmd_list_taxonomies() {
$labels = array(
\'name\' => _x( \'List Categories\', \'List Categories\' ),
\'singular_name\' => _x( \'Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search List Categories\' ),
\'all_items\' => __( \'All List Categories\' ),
\'parent_item\' => __( \'Parent List Categories\' ),
\'parent_item_colon\' => __( \'Parent List Category:\' ),
\'edit_item\' => __( \'Edit List Category\' ),
\'update_item\' => __( \'Update List Category\' ),
\'add_new_item\' => __( \'Add New List Category\' ),
\'new_item_name\' => __( \'New List Category Name\' ),
\'menu_name\' => __( \'List Categories\')
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'mmd_list_cat\' )
);
register_taxonomy( \'mmd_list_cat\', \'mmd_list\', $args );
}
add_action( \'init\', \'mmd_list_taxonomies\', 0 );
add_action( \'add_meta_boxes\', \'mmd_listings_add_entryfield\' );
function mmd_listings_add_entryfield()
{
// add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );
add_meta_box(
\'mmd_listings_List_Group\',
__( \'Manual Entry\', \'myplugin_textdomain\' ),
\'mmd_listing_EntryForm\',
\'mmd_list\',
\'normal\',
\'high\'
);
}
标准WordPress插件的代码并不引人注目。
add_action( \'admin_menu\', \'mmd_list_Define_admin_menu\' );
// Add menu items
function mmd_list_Define_admin_menu()
{
add_menu_page( \'MMD Lists\', // The page title.
\'Lists\', // The menu title displayed on dashboard.
\'manage_options\', // Minimum capability to view the menu.
\'mmd_list_options\', // Unique name used as a slug for menu item.
\'mmd_maplist_DrawAdminPage\', // A callback function used to display page content.
\'dashicons-media-spreadsheet\', // URL to custom image used as icon.
6
);
add_submenu_page(\'mmd_list_options\', // Parent Slug from add_menu_page
\'Manage Lists\', // Title of page
\'Manage Lists\', // Menu title
\'manage_options\', // Minimum capability to view the menu.
\'mmd_manage_lists_slug\', // Unqiue Slug Name
\'\' ); // Custom Post menu.
}
我只是不知道如何让自定义帖子落在插件管理菜单下,其所有子菜单包括:类别、管理列表、添加列表和适当的帖子页面等。
我尝试过各种分配,包括将子菜单回调函数留空,并在注册后使用slug名称引用它,但这只会导致出现“未知404页”代码。如果我使用主菜单页面并使用该名称,则会出现自定义贴子单个菜单项,但我无法访问插件所需的管理页面。
所有函数参考。在管理菜单中似乎没有与“父级”类似的功能。https://codex.wordpress.org/Function_Reference/register_post_type
一直在网络上搜索,主题要么是帖子类型,要么是插件类型,而不是两者的混合。
对此有何想法?