开发者

How to add custom post type to nav_menu in Wordpress?

开发者 https://www.devze.com 2023-02-19 19:42 出处:网络
I have a question. I use the new custom menus of Wordpress 3.0. And I\'m wondering how can I add c开发者_高级运维ustom post types to the menu. For now, I can just add Pages and Categories.

I have a question.

I use the new custom menus of Wordpress 3.0. And I'm wondering how can I add c开发者_高级运维ustom post types to the menu. For now, I can just add Pages and Categories.

Thanks


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.

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' )
        )
    );

How to add custom post type to nav_menu in Wordpress?

Screen shot with the custom post type named CPT Test.

0

精彩评论

暂无评论...
验证码 换一张
取 消