你有一些乱码。
我已经将您的代码重新格式化为实际有效的代码。
以下解决方案允许您为自定义Post Type菜单提供所需的菜单名称。只需更改标签“menu\\u name”。
POST TYPE
// Create the news custom post type
register_post_type(\'nwcm_news\', array(
\'labels\' => array(
\'name\' => __(\'News for clients\', \'NWCM\'),
\'singular_name\' => __(\'News\', \'NWCM\'),
\'menu_name\' => __(\'NWCM\', \'NWCM\'),
\'all_items\' => __(\'View Articles\', \'NWCM\'),
),
\'public\' => true,
\'has_archive\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'taxonomies\' => array(
\'nwcm_news_category\'
)
));
TAXONOMY
// register news taxonomy
register_taxonomy(\'nwcm_news_category\', \'nwcm_news\', array(
\'label\' => \'News Categories\',
\'labels\' => array(
\'menu_name\' => __(\'News Categories\', \'NWCM\')
),
\'rewrite\' => array(
\'slug\' => \'nwcm-news-category\'
),
\'hierarchical\' => true
));
我不能百分之百确定您是想在自己的自定义管理菜单下添加内容,还是只想更改自定义帖子类型的菜单名称。
我在menu_name
“NWCM”到labels
自定义帖子类型。
我强烈建议您通读并完全理解注册自定义帖子类型和分类的参数和参数。
EDIT: 09/05/2014
如果你想完全添加你自己的自定义管理菜单,并混入你自己的自定义帖子类型、自定义分类法和任何其他自定义管理页面。。。以下解决方案有效。请注意,这只是一个起点,你不必百分之百地做到“t”。这只是一个例子。。。我建议您修改它,以便您或您的开发人员能够理解和维护它。
Hook into init
and register Custom Post Types and Custom Taxonomies.
if ( ! function_exists( \'mbe_init\' ) ) {
function mbe_init() {
# Create the news custom post type
register_post_type( \'nwcm_news\', array(
\'labels\' => array(
\'name\' => __( \'News for clients\', \'NWCM\' ),
\'singular_name\' => __( \'News\', \'NWCM\' ),
),
\'public\' => true,
\'has_archive\' => true,
\'show_ui\' => true,
\'show_in_menu\' => false,// adding to custom menu manually
\'taxonomies\' => array(
\'nwcm_news_category\'
)
) );
# Create the news categories custom taxonomy
register_taxonomy( \'nwcm_news_category\', \'nwcm_news\', array(
\'label\' => \'News Categories\',
\'labels\' => array(
\'menu_name\' => __( \'News Categories\', \'NWCM\' )
),
\'rewrite\' => array(
\'slug\' => \'nwcm-news-category\'
),
\'hierarchical\' => true
) );
}
add_action( \'init\', \'mbe_init\' );
}
Hook into admin_menu
to create a custom parent admin menu, and add Custom Submenu Admin Pages, Custom Post Type pages, and Custom Taxonomy Pages all to the custom parent admin menu.
if ( ! function_exists( \'mbe_add_admin_menu\' ) && ! function_exists( \'mbe_display_admin_page\' ) ) {
function mbe_add_admin_menus() {
# Settings for custom admin menu
$page_title = \'News for clients\';
$menu_title = \'NWCM\';
$capability = \'post\';
$menu_slug = \'nwcm\';
$function = \'mbe_display_admin_page\';// Callback function which displays the page content.
$icon_url = \'dashicons-admin-page\';
$position = 0;
# Add custom admin menu
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
$submenu_pages = array(
# Avoid duplicate pages. Add submenu page with same slug as parent slug.
array(
\'parent_slug\' => \'nwcm\',
\'page_title\' => \'Summary of News\',
\'menu_title\' => \'Summary\',
\'capability\' => \'read\',
\'menu_slug\' => \'nwcm\',
\'function\' => \'mbe_display_admin_page\',// Uses the same callback function as parent menu.
),
# Post Type :: View All Posts
array(
\'parent_slug\' => \'nwcm\',
\'page_title\' => \'\',
\'menu_title\' => \'View News\',
\'capability\' => \'\',
\'menu_slug\' => \'edit.php?post_type=nwcm_news\',
\'function\' => null,// Doesn\'t need a callback function.
),
# Post Type :: Add New Post
array(
\'parent_slug\' => \'nwcm\',
\'page_title\' => \'\',
\'menu_title\' => \'Add News\',
\'capability\' => \'\',
\'menu_slug\' => \'post-new.php?post_type=nwcm_news\',
\'function\' => null,// Doesn\'t need a callback function.
),
# Taxonomy :: Manage News Categories
array(
\'parent_slug\' => \'nwcm\',
\'page_title\' => \'\',
\'menu_title\' => \'News Categories\',
\'capability\' => \'\',
\'menu_slug\' => \'edit-tags.php?taxonomy=nwcm_news_category&post_type=nwcm_news\',
\'function\' => null,// Doesn\'t need a callback function.
),
);
# Add each submenu item to custom admin menu.
foreach ( $submenu_pages as $submenu ) {
add_submenu_page(
$submenu[\'parent_slug\'],
$submenu[\'page_title\'],
$submenu[\'menu_title\'],
$submenu[\'capability\'],
$submenu[\'menu_slug\'],
$submenu[\'function\']
);
}
}
add_action( \'admin_menu\', \'mbe_add_admin_menus\', 1 );
/* If you add any extra custom sub menu pages which are not a Custom Post Type or a Custom Taxonomy, you will need
* to create a callback function for each of your custom submenu items you create above.
*/
# Default Admin Page for Custom Admin Menu
function mbe_display_admin_page() {
# Display custom admin page content from newly added custom admin menu.
echo \'<div class="wrap">\' . PHP_EOL;
echo \'<h2>My Custom Admin Page Title</h2>\' . PHP_EOL;
echo \'<p>This is the custom admin page created from the custom admin menu.</p>\' . PHP_EOL;
echo \'</div><!-- end .wrap -->\' . PHP_EOL;
echo \'<div class="clear"></div>\' . PHP_EOL;
}
}
Hook into parent_file
to correctly highlight your Custom Post Type and Custom Taxonomy submenu items with your custom parent menu/page.
if ( ! function_exists( \'mbe_set_current_menu\' ) ) {
function mbe_set_current_menu( $parent_file ) {
global $submenu_file, $current_screen, $pagenow;
# Set the submenu as active/current while anywhere in your Custom Post Type (nwcm_news)
if ( $current_screen->post_type == \'nwcm_news\' ) {
if ( $pagenow == \'post.php\' ) {
$submenu_file = \'edit.php?post_type=\' . $current_screen->post_type;
}
if ( $pagenow == \'edit-tags.php\' ) {
$submenu_file = \'edit-tags.php?taxonomy=nwcm_news_category&post_type=\' . $current_screen->post_type;
}
$parent_file = \'nwcm\';
}
return $parent_file;
}
add_filter( \'parent_file\', \'mbe_set_current_menu\' );
}
如果您需要任何关于这些工作原理的说明,请从头到尾阅读以下页面。
- Adding Custom Parent Admin
Menus
- Adding Custom Child Admin
Menus
- Roles and Capabilities in
WordPress
- Registering Custom Post
Types
- Registering Custom
Taxonomies
- WordPress Plugin API :: Action
Reference
- WordPress Plugin API :: Action Reference ::
init
- WordPress Plugin API :: Action Reference ::
admin_menu
- WordPress Plugin API :: Filter
Reference
- List of All WordPress Hooks (including actions and
filters)