如何在 Wordpress 中向 nav_menu 添加自定义帖子类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5446278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add custom post type to nav_menu in Wordpress?
提问by Steffi
I have a question.
我有个问题。
I use the new custom menus
of Wordpress 3.0. And I'm wondering how can I add custom post types to the menu. For now, I can just add Pages
and Categories
.
我使用的custom menus
是 Wordpress 3.0的新版本。我想知道如何将自定义帖子类型添加到菜单中。现在,我可以添加Pages
和Categories
。
Thanks
谢谢
回答by fuxia
The function register_post_type()takes an argument show_in_nav_menus
. If you set this to TRUE
you get a selector for your custom post type in the menu manager.
函数register_post_type()接受一个参数show_in_nav_menus
。如果您将其设置为,TRUE
您将在菜单管理器中获得自定义帖子类型的选择器。
Sample code
示例代码
register_post_type(
'post_type_name'
, array (
'can_export' => TRUE
, 'exclude_from_search' => FALSE
, 'has_archive' => TRUE
, 'hierarchical' => TRUE
, 'label' => 'CPT Test'
, 'menu_position' => 5
, 'public' => TRUE
, 'publicly_queryable' => TRUE
, 'query_var' => 'cpttest'
, 'rewrite' => array ( 'slug' => 'cpt-test' )
, 'show_ui' => TRUE
, 'show_in_menu' => TRUE
, 'show_in_nav_menus' => TRUE
, 'supports' => array ( 'editor', 'title' )
)
);
Screen shot with the custom post type named CPT Test.
使用名为CPT Test的自定义帖子类型的屏幕截图。