如何在选项页面下添加自定义帖子类型

时间:2013-04-02 作者:strange man

任何人请帮助我了解如何在设置菜单(option\\u页)中添加自定义帖子类型。基本上,通过使用以下各项,自定义管理菜单很容易:

\'在菜单中显示\'u\'=>\'菜单段塞\'

但我喜欢在选项页下添加此帖子类型。

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

通过传递“选项常规”,可以在“设置”菜单中添加自定义帖子类型。php“value to”“show\\u in\\u menu”参数,如下所示

Example : \'show_in_menu\' => \'options-general.php\'
完整代码:

function codex_custom_init() {
  $labels = array(
\'name\' => \'Books\',
\'singular_name\' => \'Book\',
\'add_new\' => \'Add New\',
\'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\' => \'options-general.php\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'book\' ),
\'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\' );
有关更多信息,请参阅this page.

结束

相关推荐