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

时间:2012-06-22 05:41:43

标签: php wordpress wordpress-plugin

我想知道如何在创建wordpress插件时为自定义帖子类型添加新的子菜单。 我现在所做的,我创建了一个名为'funds'的自定义帖子类型。

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
    )
);

}

此代码添加了一个名为“基金”的自定义帖子类型,下面是两个子菜单(“基金”,“添加新基金”)。我想做的是在资金下添加新的子菜单。示例我想添加“基金设置”,因此在资金下将有(基金,添加新基金,基金设置)。

我该怎么做?

1 个答案:

答案 0 :(得分:3)

你可以这样做:
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*/
);

要向页面添加设置/选项,我建议settings API
一个好的(有点长)教程如何使用它:http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-1/