adding page types in menu

时间:2012-08-16 作者:Phil Jackson

我相信我正在努力实现的目标是很容易的,但我没有掌握这里需要什么。

我想在管理面板中有一个部分。。。让我们说“页面节”

在这种情况下,我希望能够添加多种帖子类型。i、 e.让我们说

“添加成员”、“添加foo”、“添加栏”。。。

我目前有

add_action( \'init\', \'add_item\' );
add_action( \'init\', \'add_item2\' );
function add_item(){
    register_post_type(\'item1\', array(
        \'label\' => \'Item label\',
        \'public\' => true,
        \'show_ui\' => true,
        \'capability_type\' => \'page\',
        \'capabilities\' => array(

        ),
        \'hierarchical\' => true,
        \'rewrite\' => array(\'slug\' => \'puds\'),
        \'query_var\' => true,
        \'supports\' => array(
            \'title\',
            \'editor\',
            \'excerpt\',
            \'custom-fields\',
            \'revisions\',
            \'thumbnail\',
            \'author\',
            \'page-attributes\',
            \'post-formats\'
        )
    ) );
}
function add_item2(){
register_post_type(\'item2\', array(
    \'label\' => \'Item label 2\',
    \'public\' => true,
    \'show_ui\' => true,
    \'capability_type\' => \'page\',
    \'capabilities\' => array(

    ),
    \'hierarchical\' => true,
    \'rewrite\' => array(\'slug\' => \'puds\'),
    \'query_var\' => true,
    \'supports\' => array(
        \'title\',
        \'editor\',
        \'excerpt\',
        \'custom-fields\',
        \'revisions\',
        \'thumbnail\',
        \'author\',
        \'page-attributes\',
        \'post-formats\'
    )
) );
}

这将产生

enter image description here

但我想要一个菜单标题和多个菜单选择。。。

有什么想法吗?

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

抱歉,请尝试以下操作:

\'show_ui\' => false,
\'menu_position\' => \'edit.php?post_type=main_posttype or registered section\'
例如,如果您想将其置于主题下,则应为:

\'menu_position\' => \'themes.php\'
这是您的帖子类型注册。

SO网友:jepser

我想你可以在标签文档中查看如下帖子类型:

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

  );
  $args = array(
    \'labels\' => $labels,
    \'public\' => true,
    \'publicly_queryable\' => true,
    \'show_ui\' => true, 
    \'show_in_menu\' => true, 
    \'query_var\' => true,
    \'rewrite\' => true,
    \'capability_type\' => \'post\',
    \'has_archive\' => true, 
    \'hierarchical\' => false,
    \'menu_position\' => null,
    \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
  ); 
  register_post_type(\'book\',$args);
}
add_action( \'init\', \'codex_custom_init\' );
检查:http://codex.wordpress.org/Function_Reference/register_post_type

结束

相关推荐