如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:45:31  来源:igfitidea点击:

How to add custom post type to nav_menu in Wordpress?

wordpresspostmenuadmin

提问by Steffi

I have a question.

我有个问题。

I use the new custom menusof Wordpress 3.0. And I'm wondering how can I add custom post types to the menu. For now, I can just add Pagesand Categories.

我使用的custom menus是 Wordpress 3.0的新版本。我想知道如何将自定义帖子类型添加到菜单中。现在,我可以添加PagesCategories

Thanks

谢谢

回答by fuxia

The function register_post_type()takes an argument show_in_nav_menus. If you set this to TRUEyou 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

截屏

Screen shot with the custom post type named CPT Test.

使用名为CPT Test的自定义帖子类型的屏幕截图。