如何给自定义帖子类型下子菜单赋位

时间:2017-12-12 作者:Satrughna

我试图在我的自定义帖子类型下添加子菜单,我也成功了,但它显示在帖子类型下,我想在分类下显示它。如何为新创建的子菜单指定位置?

还有一个问题:单击分类法时,父菜单块不会保持激活状态。

enter image description here

这是我的密码。

<?php
add_submenu_page(\'edit.php?post_type=car\', "Package Layout Setting", "Layouts", "manage_options", "layout", "car_product_layout_setting", \'\');

function car_product_layout_setting() {
    ?>
    <div class="wrap">
        <h1>Package Layout Setting</h1>
    </div>
    <?php
}

1 个回复
最合适的回答,由SO网友:kierzniak 整理而成

如果将函数与适当的挂钩连接,则子菜单页将显示在帖子类型和分类之后。看看我的例子:

/**
 * Register event post type
 *
 * Function is used by init hook
 */
function wpse_288373_register_event_post_type() {

    $labels = array(
        \'name\' => __( \'Events\' ),
        \'singular_name\' => __( \'Event\' ),
        \'add_new\' => __( \'Add new\' ),
        \'add_new_item\' => __( \'Add new\' ),
        \'edit_item\' => __( \'Edit\' ),
        \'new_item\' => __( \'New\' ),
        \'view_item\' => __( \'View\' ),
        \'search_items\' => __( \'Search\' ),
        \'not_found\' => __( \'Not found\' ),
        \'not_found_in_trash\' => __( \'Not found Events in trash\' ),
        \'parent_item_colon\' => __( \'Parent\' ),
        \'menu_name\' => __( \'Events\' ),

    );

    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => false,
        \'supports\' => array( \'title\', \'page-attributes\' ),
        \'taxonomies\' => array(),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'show_in_nav_menus\' => false,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => array(\'slug\' => \'event\'),
        \'capability_type\' => \'post\',
    );

    register_post_type( \'event\', $args );
}

add_action( \'init\', \'wpse_288373_register_event_post_type\' );

/**
 * Register submenu
 *
 * Function is used by admin_menu hook
 */
function wpse_288373_register_submenu_page() {
    add_submenu_page(\'edit.php?post_type=event\', \'Event settings\', \'Settings\', "manage_options", \'settings\', \'wpse_288373_event_settings\', \'\');
}

add_action(\'admin_menu\', \'wpse_288373_register_submenu_page\');

/**
 * Register submenu page
 *
 * Function is used by add_submenu_page function
 */
function wpse_288373_event_settings() {
    return;
}

结束

相关推荐

Order Admin sub-menu items?

我正在使用向CPT管理菜单添加项目add_submenu_page 这很好,但它们被添加到CPT选项后的子菜单底部。我希望能够将它们放在最上面,但我想这个问题也可以应用于订购所有基于管理员的子菜单项。我所尝试的(不起作用,我尝试了几种变体),function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( \'edi