【问题标题】:Adding a sub-menu to a custom post type将子菜单添加到自定义帖子类型
【发布时间】:2018-05-30 03:21:16
【问题描述】:

我想知道如何在创建 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
    )
);

}

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

我该怎么做?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

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

    【讨论】:

    • @CHiRiLo 我想你想创建设置?我推荐 settigns API,请参阅我的更新答案。
    • 是的。但是如果我可以添加一个元框呢?谁知道也许有人也想这样做。
    • 问题应该是 ''what''(function) do you want to do not ''how''(technique) 。出于这个问题,您想要构建它的“如何”。那你想做什么?元框如何比设置更好?这将很难做到。
    • 如果我将自定义帖子类型与 sub_menu_page 合并,则添加新选项不会显示在管理面板的左侧。
    • @Urocks 如果这是一个问题,请打开一个新问题。
    猜你喜欢
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多