我想知道如何在创建wordpress插件时为自定义帖子类型添加新的子菜单。我现在所做的是,我创建了一个名为"资金"的自定义帖子类型。
add_action( 'init', 'wnm_add_funds' );
function wnm_add_funds() {
register_post_type('wnm_funds',
array(
'labels' => array(
'name' => __( 'Funds' ),
'add_new' => __( 'Add New Fund' ),
'add_new_item' => __( 'Add New Fund' ),
'edit_item' => __( 'Edit Fund' )),
'public' => true,
'has_archive' => true,
'menu_position' => 100
)
);
}
此代码添加了一个名为"资金"的自定义帖子类型,其下有两个子菜单("资金","添加新资金")。我想做的是在资金下添加新的子菜单。例如,我想添加"资金设置",因此在资金下将有(资金,添加新基金,基金设置)。
我该怎么做?
你可以用:
http://codex.wordpress.org/Function_Reference/add_submenu_page
http://codex.wordpress.org/Roles_and_Capabilities我不知道该功能是否适合您的事业,但这将起作用
<?php
add_submenu_page(
'edit.php?post_type=wnm_funds',
'Fund Settings', /*page title*/
'Settings', /*menu title*/
'manage_options', /*roles and capabiliyt needed*/
'wnm_fund_set',
'CALLBACK_FUNCTION_NAME' /*replace with your own function*/
);
要向页面添加设置/选项,我推荐设置 API
一个很好的(有点长)如何使用它的教程:http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-1/