wordpress菜单和自定义帖子类型的子菜单

时间:2016-08-26 13:21:50

标签: wordpress admin submenu

我有以下菜单和子菜单结构。如何添加一个新菜单和内部我的自定义帖子类型菜单与子选项。我做得不对劲。善意的建议。

以下是结构。 enter image description here

以下是代码

function wpdocs_register_my_custom_menu_page(){
    add_menu_page( 
        __( 'Custom Menu Title', 'textdomain' ),
        'SANHA Menu',
        'manage_options',
        'custompage',
        'my_custom_menu_page',
        plugins_url( 'myplugin/images/small-flag.png' ),
        6
    ); 
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );


add_action( 'init', 'salman' );
function salman(){
  register_post_type( 'salu',
    array(
      'labels' => array(
        'name' => __( 'Salmans' ),
        'singular_name' => __( 'salman' )
      ),
      'public' => true,
      'has_archive' => true,
      'menu_icon' => 'dashicons-media-text',
      'hierarchical'      => true,
      'show_ui'           => true,
      'show_admin_column' => true,
      'show_in_menu' => 'edit.php',
      'query_var'         => true,
      'rewrite' => array('slug' => 'restaurants',),
      'supports'=> array( 'title', 'editor', 'excerpt', 'author', 'thumbnail',),
    )
  );
}

3 个答案:

答案 0 :(得分:0)

您需要注册自定义帖子类型,并且必须为您的帖子类型提供$args,以便它显示管理面板中的所有选项,并且它被称为custom post type,您可以按照以下代码要有更好的理解

function my_custom_post_sanha() {
$labels = array(
'name'               => _x( 'SANHA Menu', 'post type general name' ),
'singular_name'      => _x( 'SANHA Menu', 'post type singular name' ),
'add_new'            => _x( 'Add New', 'book' ),
'add_new_item'       => __( 'Add New SANHA Menu' ),
'edit_item'          => __( 'Edit SANHA Menu' ),
'new_item'           => __( 'New SANHA Menu' ),
'all_items'          => __( 'All SANHA Menu' ),
'view_item'          => __( 'View SANHA Menu' ),
'search_items'       => __( 'Search SANHA Menu' ),
'not_found'          => __( 'No SANHA Menu found' ),
'not_found_in_trash' => __( 'No SANHA Menu found in the Trash' ), 
'parent_item_colon'  => '',
'menu_name'          => 'SANHA Menu'
);

$args = array(
'labels'        => $labels,
'description'   => 'Holds our SANHA Menu and SANHA Menu specific data',
'public'        => true,
'menu_position' => 15,
'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive'   => true,
);

register_post_type( 'sanha_menu', $args ); 
}

add_action( 'init', 'my_custom_post_sanha' );

function my_taxonomies_sanha() {
  $labels = array(
'name'              => _x( 'SANHA Menu Categories', 'taxonomy general name' ),
'singular_name'     => _x( 'SANHA Menu Category', 'taxonomy singular name' ),
'search_items'      => __( 'Search SANHA Menu Categories' ),
'all_items'         => __( 'All SANHA Menu Categories' ),
'parent_item'       => __( 'Parent SANHA Menu Category' ),
'parent_item_colon' => __( 'Parent SANHA Menu Category:' ),
'edit_item'         => __( 'Edit SANHA Menu Category' ), 
'update_item'       => __( 'Update SANHA Menu Category' ),
'add_new_item'      => __( 'Add New SANHA Menu Category' ),
'new_item_name'     => __( 'New SANHA Menu Category' ),
'menu_name'         => __( 'SANHA Menu Categories' ),
);
$args = array(
 'labels' => $labels,
 'hierarchical' => true,
);
register_taxonomy( 'sanha_category', 'sanha_menu', $args );
register_taxonomy( 'sanha_tag', 'sanha_menu' );
}
add_action( 'init', 'my_taxonomies_sanha', 0 );

答案 1 :(得分:0)

enter image description here

仅显示产品自定义类型...菜单和第一级的第二级如何是我的自定义meny' ???

答案 2 :(得分:0)

Brother全红色突出显示的菜单可以进入蓝色突出显示的菜单吗?

enter image description here

相关问题