php – WordPress在自定义管理菜单下显示分类

我正在尝试在管理菜单项下显示自定义分类,该菜单项只是一个页面,即http://example.com/wp-admin/admin.php?page=bla.

根据wordpress Dev.在register_taxonomy下show_in_menu的页面,它说如下:

‘some string’ – If an existing top level page such as ‘tools.PHP’ or ‘edit.PHP?post_type=page’, the post type will be placed as a sub menu of that.

这是否意味着除了那些以外的任何东西都不能显示分类法?

PHP

<?PHP
// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_book_taxonomies', 0 );

// create two taxonomies, genres and writers for the post type "book"
function create_book_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name'              => _x( 'Genres', 'taxonomy general name' ),
        'singular_name'     => _x( 'Genre', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Genres' ),
        'all_items'         => __( 'All Genres' ),
        'parent_item'       => __( 'Parent Genre' ),
        'parent_item_colon' => __( 'Parent Genre:' ),
        'edit_item'         => __( 'Edit Genre' ),
        'update_item'       => __( 'Update Genre' ),
        'add_new_item'      => __( 'Add New Genre' ),
        'new_item_name'     => __( 'New Genre Name' ),
        'menu_name'         => __( 'Genre' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_in_menu'      => 'bla', // not working | tried admin.PHP?page=bla as well, also not working
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'genre' ),
    );

    register_taxonomy( 'genre', array( 'book' ), $args );
}

解决方法:

我已找到解决此问题的方法,代码如下:

    add_action( 'admin_menu', 'shmeh_menu' );
    add_action( 'parent_file', 'menu_highlight' );

    function shmeh_menu() {
        add_submenu_page( 'bla', 'Shmeh', 'Shmeh', 'manage_options', 'edit-tags.PHP?taxonomy=shmeh');
    }

    function menu_highlight( $parent_file ) {
        global $current_screen;

        $taxonomy = $current_screen->taxonomy;
        if ( $taxonomy == 'shmeh' ) {
            $parent_file = 'bla';
        }

        return $parent_file;
    }

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...