自定义帖子类型、分类和管理栏

时间:2013-01-30 作者:Baylock

我的WordPress网站上有两种帖子类型:

“Articles”是一种经典的帖子类型,“Breves”是一种自定义的帖子类型,我希望它们共享相同的标准类别和帖子标签,因此这就是我创建“Breve”自定义帖子类型作为插件的方式:

function breve_register() {

    $labels = array(
        \'name\' => _x(\'Brèves\', \'post type general name\'),
        \'singular_name\' => _x(\'Brève\', \'post type singular name\'),
        \'add_new\' => _x(\'Ajouter\', \'portfolio item\'),
        \'add_new_item\' => __(\'Ajouter une brève\'),
        \'edit_item\' => __(\'Editer une brève\'),
        \'new_item\' => __(\'Nouvelle brève\'),
        \'view_item\' => __(\'Voir la brève\'),
        \'search_items\' => __(\'Rechercher une brève\'),
        \'not_found\' =>  __(\'Aucune brève trouvée\'),
        \'not_found_in_trash\' => __(\'Aucune brève trouvée dans la corbeille\'),
        \'parent_item_colon\' => \'\'
    );

    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\',
        \'hierarchical\' => false,
        \'menu_position\' => null,
        \'supports\' => array(\'title\',\'editor\',\'thumbnail\'),
        \'taxonomies\' => array(\'category\', \'post_tag\')
      ); 

    register_post_type( \'breve\' , $args );
}
add_action(\'init\', \'breve_register\');
当我创建一篇新的“breve”文章时,我可以选择一个类别并定义一个post标记,就像我创建一篇新的“article”一样。

My concern:

在注册“Breves”分类之前,只有“Articles”部分在左侧管理菜单栏上显示“Categories”和“Post tags”链接。现在,这两个链接也出现在左侧管理菜单栏的“Breves”部分下,这是多余的。

至少,我想在左边的管理菜单栏上只看到“文章”的“类别”和“帖子标签”链接,而不是“Breves”的链接。

但如果可能的话(这太棒了),我希望“类别”和“帖子标签”只在管理菜单栏上显示一次,与“文章”和“短消息”在同一级别,而不是在这两个部分中的任何一个。这是有道理的,因为现在“类别”和“帖子标签”由多个部分共享,所以将它们放在一个部分下会引发一个人机工程学和逻辑问题。

我可以问你一些关于如何实现这一点的帮助吗?

非常感谢。

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

管理菜单有点麻烦,它不是很灵活,需要大修。看见this ongoing ticket 关于这个问题。

您可以使用remove_submenu_page 函数删除类别和标记子菜单页,然后通过在顶层添加它们add_menu_page. 例如,这将删除“类别”子菜单并将其移至顶层:

function wpa83704_adjust_the_wp_menu() {
    remove_submenu_page(
        \'edit.php\',
        \'edit-tags.php?taxonomy=category\'
    );
    add_menu_page(
        \'Categories\',
        \'Categories\',
        \'add_users\',
        \'edit-tags.php?taxonomy=category\',
        \'\',
        \'div\',
        6
    );
}
add_action( \'admin_menu\', \'wpa83704_adjust_the_wp_menu\', 999 );
不过,这里有几个问题。

WordPress用于菜单项的图标无法用于这些新菜单项,您需要图像的URL,或者可以将其设置为div 您必须通过以下方式添加一些CSSadmin_head 获取您想要的图标。

选择新类别顶级菜单项时,将突出显示错误的菜单项。目前唯一解决此问题的方法是通过JavaScript。See this answer 需要一些代码来解决这个问题。

SO网友:liying

为什么不试试这个插件:Custom Post Type UI,它允许您添加任何想要的帖子类型,还可以为每个帖子类型分离分类法和类别

下面是我在创建插件之前在一个项目中写的内容,希望对您有所帮助:

    <?php
    define(\'CUSTOM_POST_TYPE1\',\'event\');  //PLEASE DON\'T CHANGE THIS CONTENT max. 20 characters, can not contain capital letters or spaces
    define(\'CUSTOM_CATEGORY_TYPE1\',\'eventcategory\');  //PLEASE DON\'T CHANGE THIS CONTENT
    define(\'CUSTOM_TAG_TYPE1\',\'eventtags\');  //PLEASE DON\'T CHANGE THIS CONTENT


    define(\'CUSTOM_POST_TYPE2\',\'activity\');  //PLEASE DON\'T CHANGE THIS CONTENT max. 20 characters, can not contain capital letters or spaces
    define(\'CUSTOM_CATEGORY_TYPE2\',\'activitycategory\');  //PLEASE DON\'T CHANGE THIS CONTENT
    define(\'CUSTOM_TAG_TYPE2\',\'activitytags\');  //PLEASE DON\'T CHANGE THIS CONTENT


    define(\'CUSTOM_POST_TYPE3\',\'product\');  //PLEASE DON\'T CHANGE THIS CONTENT max. 20 characters, can not contain capital letters or spaces
    define(\'CUSTOM_CATEGORY_TYPE3\',\'productcategory\');  //PLEASE DON\'T CHANGE THIS CONTENT
    define(\'CUSTOM_TAG_TYPE3\',\'producttags\');  //PLEASE DON\'T CHANGE THIS CONTENT






    //////////CUSTOM POST TYPE LABELS////////
    define(\'CUSTOM_TAXONOMY_SEARCH_ITEM\',__(\'Search Category\'));
    define(\'CUSTOM_POST_EDIT\',__(\'Edit\'));


    define(\'CUSTOM_POST_LABEL\',__(\'Events\'));
    define(\'CUSTOM_POST_LABEL2\',__(\'Activity\'));
    define(\'CUSTOM_POST_LABEL3\',__(\'Product\'));

    define(\'CUSTOM_POST_NAME\',__(\'Events\'));
    define(\'CUSTOM_POST_NAME2\',__(\'Activity\'));
    define(\'CUSTOM_POST_NAME3\',__(\'Product\'));

    define(\'CUSTOM_POST_SINGULAR_NAME\',__(\'Event\'));
    define(\'CUSTOM_POST_SINGULAR_NAME2\',__(\'Activity\'));
    define(\'CUSTOM_POST_SINGULAR_NAME3\',__(\'Product\'));

    define(\'CUSTOM_POST_ADD_NEW\',__(\'Add Event\'));
    define(\'CUSTOM_POST_ADD_NEW2\',__(\'Add Activity\'));
    define(\'CUSTOM_POST_ADD_NEW3\',__(\'Add Product\'));

    define(\'CUSTOM_POST_ADD_NEW_ITEM\',__(\'Add New Event\'));
    define(\'CUSTOM_POST_ADD_NEW_ITEM2\',__(\'Add New Activity\'));
    define(\'CUSTOM_POST_ADD_NEW_ITEM3\',__(\'Add New Product\'));


    define(\'CUSTOM_POST_EDIT_ITEM\',__(\'Edit Event\'));
    define(\'CUSTOM_POST_EDIT_ITEM2\',__(\'Edit Activity\'));
    define(\'CUSTOM_POST_EDIT_ITEM3\',__(\'Edit Product\'));

    define(\'CUSTOM_POST_NEW_ITEM\',__(\'New Event\'));
    define(\'CUSTOM_POST_NEW_ITEM2\',__(\'New Activity\'));
    define(\'CUSTOM_POST_NEW_ITEM3\',__(\'New Product\'));

    define(\'CUSTOM_POST_VIEW_ITEM\',__(\'View Event\'));
    define(\'CUSTOM_POST_VIEW_ITEM2\',__(\'View Activity\'));
    define(\'CUSTOM_POST_VIEW_ITEM3\',__(\'View Product\'));

    define(\'CUSTOM_POST_SEARCH_ITEM\',__(\'Search Events\'));
    define(\'CUSTOM_POST_SEARCH_ITEM2\',__(\'Search Activity\'));
    define(\'CUSTOM_POST_SEARCH_ITEM3\',__(\'Search Product\'));

    define(\'CUSTOM_POST_NOT_FOUND\',__(\'No Events found\'));
    define(\'CUSTOM_POST_NOT_FOUND2\',__(\'No Activity found\'));
    define(\'CUSTOM_POST_NOT_FOUND3\',__(\'No Product found\'));

    define(\'CUSTOM_POST_NOT_FOUND_IN_TRASH\',__(\'No Events found in trash\'));
    define(\'CUSTOM_POST_NOT_FOUND_IN_TRASH2\',__(\'No Activity found in trash\'));
    define(\'CUSTOM_POST_NOT_FOUND_IN_TRASH3\',__(\'No Product found in trash\'));

    define(\'CUSTOM_TAXONOMY_LABEL\',__(\'Event Category\'));
    define(\'CUSTOM_TAXONOMY_LABEL2\',__(\'Activity Group\'));
    define(\'CUSTOM_TAXONOMY_LABEL3\',__(\'Activity Product\'));

    define(\'CUSTOM_TAXONOMY_NAME\',__(\'Event Categories\'));
    define(\'CUSTOM_TAXONOMY_NAME2\',__(\'Activity Groupes\'));
    define(\'CUSTOM_TAXONOMY_NAME3\',__(\'Product Categories\'));

    define(\'CUSTOM_TAXONOMY_SINGULAR_NAME\',__(\'Event Category\'));
    define(\'CUSTOM_TAXONOMY_SINGULAR_NAME2\',__(\'Activity Group\'));
    define(\'CUSTOM_TAXONOMY_SINGULAR_NAME3\',__(\'Product Category\'));


    define(\'CUSTOM_TAXONOMY_POPULAR_ITEM\',__(\'Popular Event Categories\'));
    define(\'CUSTOM_TAXONOMY_POPULAR_ITEM2\',__(\'Popular Activity Groups\'));
    define(\'CUSTOM_TAXONOMY_POPULAR_ITEM3\',__(\'Popular Product Categories\'));

    define(\'CUSTOM_TAXONOMY_ALL_ITEMS\',__(\'All Event Categories\'));
    define(\'CUSTOM_TAXONOMY_ALL_ITEMS2\',__(\'All Activity Groups\'));
    define(\'CUSTOM_TAXONOMY_ALL_ITEMS3\',__(\'All Product Categories\'));

    define(\'CUSTOM_TAXONOMY_PARENT_ITEM\',__(\'Parent Event Category\'));
    define(\'CUSTOM_TAXONOMY_PARENT_ITEM2\',__(\'Parent Activity Group\'));
    define(\'CUSTOM_TAXONOMY_PARENT_ITEM3\',__(\'Parent Product Category\'));

    define(\'CUSTOM_TAXONOMY_PARENT_ITEM_COLON\',__(\'Parent Event Category:\'));
    define(\'CUSTOM_TAXONOMY_PARENT_ITEM_COLON2\',__(\'Parent Activity Group:\'));
    define(\'CUSTOM_TAXONOMY_PARENT_ITEM_COLON3\',__(\'Parent Activity Category:\'));

    define(\'CUSTOM_TAXONOMY_EDIT_ITEM\',__(\'Edit Event Category\'));
    define(\'CUSTOM_TAXONOMY_EDIT_ITEM2\',__(\'Edit Activity Group\'));
    define(\'CUSTOM_TAXONOMY_EDIT_ITEM3\',__(\'Edit Product Category\'));

    define(\'CUSTOM_TAXONOMY_UPDATE_ITEM\',__(\'Update Event Category\'));
    define(\'CUSTOM_TAXONOMY_UPDATE_ITEM2\',__(\'Update Activity Group\'));
    define(\'CUSTOM_TAXONOMY_UPDATE_ITEM3\',__(\'Update Product Category\'));

    define(\'CUSTOM_TAXONOMY_ADD_NEW_ITEM\',__(\'Add New Event Category\'));
    define(\'CUSTOM_TAXONOMY_ADD_NEW_ITEM2\',__(\'Add New Activity Group\'));
    define(\'CUSTOM_TAXONOMY_ADD_NEW_ITEM3\',__(\'Add New Product Category\'));

    define(\'CUSTOM_TAXONOMY_NEW_ITEM_NAME\',__(\'New Event Category Name\'));
    define(\'CUSTOM_TAXONOMY_NEW_ITEM_NAME2\',__(\'New Activity Group Name\'));
    define(\'CUSTOM_TAXONOMY_NEW_ITEM_NAME3\',__(\'New Product Category Name\'));

    define(\'CUSTOM_TAG_LABEL\',__(\'Event Tags\'));
    define(\'CUSTOM_TAG_LABEL2\',__(\'Activity Tags\'));
    define(\'CUSTOM_TAG_LABEL3\',__(\'Product Tags\'));

    define(\'CUSTOM_TAG_NAME\',__(\'Event Tags\'));
    define(\'CUSTOM_TAG_NAME2\',__(\'Activity Tags\'));
    define(\'CUSTOM_TAG_NAME3\',__(\'Product Tags\'));

    define(\'CUSTOM_TAG_SINGULAR_NAME\',__(\'Event Tags\'));
    define(\'CUSTOM_TAG_SINGULAR_NAME2\',__(\'Activity Tags\'));
    define(\'CUSTOM_TAG_SINGULAR_NAME3\',__(\'Product Tags\'));

    define(\'CUSTOM_TAG_SEARCH_ITEMS\',__(\'Search Event Tags\'));
    define(\'CUSTOM_TAG_SEARCH_ITEMS2\',__(\'Search Activity Tags\'));
    define(\'CUSTOM_TAG_SEARCH_ITEM3\',__(\'Search Product Tags\'));

    define(\'CUSTOM_TAG_POPULAR_ITEMS\',__(\'Popular Event Tags\'));
    define(\'CUSTOM_TAG_POPULAR_ITEMS2\',__(\'Popular Activity Tags\'));
    define(\'CUSTOM_TAG_POPULAR_ITEMS3\',__(\'Popular Product Tags\'));

    define(\'CUSTOM_TAG_ALL_ITEMS\',__(\'All Event Tags\'));
    define(\'CUSTOM_TAG_ALL_ITEMS2\',__(\'All Activity Tags\'));
    define(\'CUSTOM_TAG_ALL_ITEMS3\',__(\'All Product Tags\'));

    define(\'CUSTOM_TAG_PARENT_ITEM\',__(\'Parent Event Tags\'));
    define(\'CUSTOM_TAG_PARENT_ITEM2\',__(\'Parent Activity Tags\'));
    define(\'CUSTOM_TAG_PARENT_ITEM3\',__(\'Parent Product Tags\'));

    define(\'CUSTOM_TAG_PARENT_ITEM_COLON\',__(\'Parent Event Tags:\'));
    define(\'CUSTOM_TAG_PARENT_ITEM_COLON2\',__(\'Parent Activity Tags:\'));
    define(\'CUSTOM_TAG_PARENT_ITEM_COLON3\',__(\'Parent Product Tags:\'));

    define(\'CUSTOM_TAG_EDIT_ITEM\',__(\'Edit Event Tags\'));
    define(\'CUSTOM_TAG_EDIT_ITEM2\',__(\'Edit Activity Tags\'));
    define(\'CUSTOM_TAG_EDIT_ITEM3\',__(\'Edit Product Tags\'));

    define(\'CUSTOM_TAG_UPDATE_ITEM\',__(\'Update Event Tags\'));
    define(\'CUSTOM_TAG_UPDATE_ITEM2\',__(\'Update Activity Tags\'));
    define(\'CUSTOM_TAG_UPDATE_ITEM3\',__(\'Update Product Tags\'));

    define(\'CUSTOM_TAG_ADD_NEW_ITEM\',__(\'Add New Event Tags\'));
    define(\'CUSTOM_TAG_ADD_NEW_ITEM2\',__(\'Add New Activity Tags\'));
    define(\'CUSTOM_TAG_ADD_NEW_ITEM3\',__(\'Add New Product Tags\'));

    define(\'CUSTOM_TAG_NEW_ITEM_NAME\',__(\'New Event Tags Name\'));
    define(\'CUSTOM_TAG_NEW_ITEM_NAME2\',__(\'New Activity Tags Name\'));
    define(\'CUSTOM_TAG_NEW_ITEM_NAME3\',__(\'New Product Tags Name\'));


    define(\'CUSTOM_TAXONOMY_SEARCH_ITEM2\',__(\'Search Groups\'));

    ?>


    <?php
    add_action("init", "custom_posttype_menu_wp_admin");
    function custom_posttype_menu_wp_admin(){
    //===============EVENT SECTION START================
        register_post_type( CUSTOM_POST_TYPE1, 
                    array(  \'label\'             => CUSTOM_POST_LABEL,
                            \'labels\'            => array(   \'name\'                  => CUSTOM_POST_NAME,//
                                                            \'singular_name\'         => CUSTOM_POST_SINGULAR_NAME,
                                                            \'add_new\'               =>  CUSTOM_POST_ADD_NEW,
                                                            \'add_new_item\'          =>  CUSTOM_POST_ADD_NEW_ITEM,
                                                            \'edit\'                  =>  CUSTOM_POST_EDIT,
                                                            \'edit_item\'             =>  CUSTOM_POST_EDIT_ITEM,
                                                            \'new_item\'              =>  CUSTOM_POST_NEW_ITEM,
                                                            \'view_item\'             =>  CUSTOM_POST_VIEW_ITEM,
                                                            \'search_items\'          =>  CUSTOM_POST_SEARCH_ITEM,
                                                            \'not_found\'             =>  CUSTOM_POST_NOT_FOUND,
                                                            \'not_found_in_trash\'    =>  CUSTOM_POST_NOT_FOUND_IN_TRASH  ),
                            \'public\'            => true,
                            \'can_export\'        => true,
                            \'show_ui\'           => true, // UI in admin panel
                            \'_builtin\'          => false, // It\'s a custom post type, not built in
                            \'_edit_link\'        => \'post.php?post=%d\',
                            \'capability_type\'   => \'post\',
                            \'menu_icon\'         => get_bloginfo(\'template_url\').\'/images/favicon.ico\',
                            \'hierarchical\'      => false,
                            \'rewrite\'           => array(   "slug" => CUSTOM_POST_TYPE1 ), // Permalinks
                            \'query_var\'         => CUSTOM_POST_TYPE1, // This goes to the WP_Query schema
                            \'supports\'          => array(   \'title\',
                                                            \'author\', 
                                                            \'excerpt\',
                                                            \'thumbnail\',
                                                            \'comments\',
                                                            \'editor\', 
                                                            \'trackbacks\',
                                                            \'custom-fields\',
                                                            \'revisions\') ,
                            \'show_in_nav_menus\' => true ,
                            \'taxonomies\'        => array(CUSTOM_CATEGORY_TYPE1,CUSTOM_TAG_TYPE1),
                            \'menu_position\' => 4
                        )
        );

    // Register custom taxonomy
        register_taxonomy(  CUSTOM_CATEGORY_TYPE1, 
                    array(  CUSTOM_POST_TYPE1   ), 
                    array ( "hierarchical"      => true, 
                            "label"             => CUSTOM_TAXONOMY_LABEL, 
                            \'labels\'            => array(   \'name\'              =>  CUSTOM_TAXONOMY_NAME,
                                                            \'singular_name\'     =>  CUSTOM_TAXONOMY_SINGULAR_NAME,
                                                            \'search_items\'      =>  CUSTOM_TAXONOMY_SEARCH_ITEM,
                                                            \'popular_items\'     =>  CUSTOM_TAXONOMY_POPULAR_ITEM,
                                                            \'all_items\'         =>  CUSTOM_TAXONOMY_ALL_ITEMS,
                                                            \'parent_item\'       =>  CUSTOM_TAXONOMY_PARENT_ITEM,
                                                            \'parent_item_colon\' =>  CUSTOM_TAXONOMY_PARENT_ITEM_COLON,
                                                            \'edit_item\'         =>  CUSTOM_TAXONOMY_EDIT_ITEM,
                                                            \'update_item\'       =>  CUSTOM_TAXONOMY_UPDATE_ITEM,
                                                            \'add_new_item\'      =>  CUSTOM_TAXONOMY_ADD_NEW_ITEM,
                                                            \'new_item_name\'     =>  CUSTOM_TAXONOMY_NEW_ITEM_NAME   ), 
                            \'public\'            => true,
                            \'show_ui\'           => true,
                            "rewrite"           => true )
        );


        register_taxonomy(CUSTOM_TAG_TYPE1, 
                    array(  CUSTOM_POST_TYPE1   ), 
                    array(  "hierarchical"      => false, 
                            "label"             => CUSTOM_TAG_LABEL, 
                            \'labels\'            => array(   \'name\'              => CUSTOM_TAG_NAME,
                                                            \'singular_name\'     => CUSTOM_TAG_SINGULAR_NAME,
                                                            \'search_items\'      => CUSTOM_TAG_SEARCH_ITEMS,
                                                            \'popular_items\'     => CUSTOM_TAG_POPULAR_ITEMS,
                                                            \'all_items\'         => CUSTOM_TAG_ALL_ITEMS,
                                                            \'parent_item\'       => CUSTOM_TAG_PARENT_ITEM,
                                                            \'parent_item_colon\' => CUSTOM_TAG_PARENT_ITEM_COLON,
                                                            \'edit_item\'         => CUSTOM_TAG_EDIT_ITEM,
                                                            \'update_item\'       => CUSTOM_TAG_UPDATE_ITEM,
                                                            \'add_new_item\'      => CUSTOM_TAG_ADD_NEW_ITEM,
                                                            \'new_item_name\'     => CUSTOM_TAG_NEW_ITEM_NAME ),  
                            \'public\'            => true,
                            \'show_ui\'           => true,
                            "rewrite"           => true )
    );
    //===============EVENT SECTION END================

    //===============ACTIVE SECTION START================
        register_post_type( CUSTOM_POST_TYPE2,
                    array(  \'label\'             => CUSTOM_POST_LABEL2,
                            \'labels\'            => array(   
                                        \'name\'                  =>  CUSTOM_POST_NAME2,//
                                        \'singular_name\'         =>  CUSTOM_POST_SINGULAR_NAME2,
                                        \'add_new\'               =>  CUSTOM_POST_ADD_NEW2,
                                        \'add_new_item\'          =>  CUSTOM_POST_ADD_NEW_ITEM2,
                                        \'edit\'                  =>  CUSTOM_POST_EDIT,
                                        \'edit_item\'             =>  CUSTOM_POST_EDIT_ITEM2,
                                        \'new_item\'              =>  CUSTOM_POST_NEW_ITEM2,
                                        \'view_item\'             =>  CUSTOM_POST_VIEW_ITEM2,
                                        \'search_items\'          =>  CUSTOM_POST_SEARCH_ITEM2,
                                        \'not_found\'             =>  CUSTOM_POST_NOT_FOUND2,
                                        \'not_found_in_trash\'    =>  CUSTOM_POST_NOT_FOUND_IN_TRASH2 
                            ),
                            \'public\'            => true,
                            \'can_export\'        => true,
                            \'show_ui\'           => true, // UI in admin panel
                            \'_builtin\'          => false, // It\'s a custom post type, not built in
                            \'_edit_link\'        => \'post.php?post=%d\',
                            \'capability_type\'   => \'post\',
                            \'menu_icon\'         => get_bloginfo(\'template_url\').\'/images/activity.ico\',
                            \'hierarchical\'      => false,
                            \'rewrite\'           => array(   "slug" => CUSTOM_POST_TYPE2 ), // Permalinks
                            \'query_var\'         => CUSTOM_POST_TYPE2, // This goes to the WP_Query schema
                            \'supports\'          => array(   
                                                    \'title\',
                                                    \'author\',
                                                    \'excerpt\',
                                                    \'thumbnail\',
                                                    \'comments\',
                                                    \'editor\',
                                                    \'trackbacks\',
                                                    \'custom-fields\',
                                                    \'revisions\'
                            ) ,
                            \'show_in_nav_menus\' => true ,
                            \'taxonomies\'        => array(CUSTOM_CATEGORY_TYPE2,CUSTOM_TAG_TYPE2),
                            \'menu_position\' => 5
                    )
        );

    // Register custom taxonomy
    register_taxonomy(  CUSTOM_CATEGORY_TYPE2,
            array(  CUSTOM_POST_TYPE2   ),
            array ( 
                    "hierarchical"      => true,
                    "label"             => CUSTOM_TAXONOMY_LABEL2,
                    \'labels\'            => array(   
                                \'name\'              =>  CUSTOM_TAXONOMY_NAME2,
                                \'singular_name\'     =>  CUSTOM_TAXONOMY_SINGULAR_NAME2,
                                \'search_items\'      =>  CUSTOM_TAXONOMY_SEARCH_ITEM2,
                                \'popular_items\'     =>  CUSTOM_TAXONOMY_POPULAR_ITEM2,
                                \'all_items\'         =>  CUSTOM_TAXONOMY_ALL_ITEMS2,
                                \'parent_item\'       =>  CUSTOM_TAXONOMY_PARENT_ITEM2,
                                \'parent_item_colon\' =>  CUSTOM_TAXONOMY_PARENT_ITEM_COLON2,
                                \'edit_item\'         =>  CUSTOM_TAXONOMY_EDIT_ITEM2,
                                \'update_item\'       =>  CUSTOM_TAXONOMY_UPDATE_ITEM2,
                                \'add_new_item\'      =>  CUSTOM_TAXONOMY_ADD_NEW_ITEM2,
                                \'new_item_name\'     =>  CUSTOM_TAXONOMY_NEW_ITEM_NAME2  
                    ),
                    \'public\'            => true,
                    \'show_ui\'           => true,
                    "rewrite"           => true 
            )
    );


    register_taxonomy(CUSTOM_TAG_TYPE2,
                    array(  CUSTOM_POST_TYPE2   ),
                    array(
                        "hierarchical"      => false,
                        "label"             => CUSTOM_TAG_LABEL2,
                        \'labels\'            => array(   \'name\'              => CUSTOM_TAG_NAME2,
                        \'singular_name\'     => CUSTOM_TAG_SINGULAR_NAME2,
                        \'search_items\'      => CUSTOM_TAG_SEARCH_ITEMS2,
                        \'popular_items\'     => CUSTOM_TAG_POPULAR_ITEMS2,
                        \'all_items\'         => CUSTOM_TAG_ALL_ITEMS2,
                        \'parent_item\'       => CUSTOM_TAG_PARENT_ITEM2,
                        \'parent_item_colon\' => CUSTOM_TAG_PARENT_ITEM_COLON2,
                        \'edit_item\'         => CUSTOM_TAG_EDIT_ITEM2,
                        \'update_item\'       => CUSTOM_TAG_UPDATE_ITEM2,
                        \'add_new_item\'      => CUSTOM_TAG_ADD_NEW_ITEM2,
                        \'new_item_name\'     => CUSTOM_TAG_NEW_ITEM_NAME2    ),
                        \'public\'            => true,
                        \'show_ui\'           => true,
                        "rewrite"           => true 
                   )
    );
    //===============ACTIVE SECTION END================


    //===============PRODUCT SECTION START================
        register_post_type( CUSTOM_POST_TYPE3,
                    array(  \'label\'             => CUSTOM_POST_LABEL3,
                            \'labels\'            => array(   
                                        \'name\'                  =>  CUSTOM_POST_NAME3,//
                                        \'singular_name\'         =>  CUSTOM_POST_SINGULAR_NAME3,
                                        \'add_new\'               =>  CUSTOM_POST_ADD_NEW3,
                                        \'add_new_item\'          =>  CUSTOM_POST_ADD_NEW_ITEM3,
                                        \'edit\'                  =>  CUSTOM_POST_EDIT,
                                        \'edit_item\'             =>  CUSTOM_POST_EDIT_ITEM3,
                                        \'new_item\'              =>  CUSTOM_POST_NEW_ITEM3,
                                        \'view_item\'             =>  CUSTOM_POST_VIEW_ITEM3,
                                        \'search_items\'          =>  CUSTOM_POST_SEARCH_ITEM3,
                                        \'not_found\'             =>  CUSTOM_POST_NOT_FOUND3,
                                        \'not_found_in_trash\'    =>  CUSTOM_POST_NOT_FOUND_IN_TRASH3 
                            ),
                            \'public\'            => true,
                            \'can_export\'        => true,
                            \'show_ui\'           => true, // UI in admin panel
                            \'_builtin\'          => false, // It\'s a custom post type, not built in
                            \'_edit_link\'        => \'post.php?post=%d\',
                            \'capability_type\'   => \'post\',
                            \'menu_icon\'         => get_bloginfo(\'template_url\').\'/images/product.png\',
                            \'hierarchical\'      => false,
                            \'rewrite\'           => array(   "slug" => CUSTOM_POST_TYPE3 ), // Permalinks
                            \'query_var\'         => CUSTOM_POST_TYPE3, // This goes to the WP_Query schema
                            \'supports\'          => array(   
                                                    \'title\',
                                                    \'author\',
                                                    \'excerpt\',
                                                    \'thumbnail\',
                                                    \'comments\',
                                                    \'editor\',
                                                    \'trackbacks\',
                                                    \'custom-fields\',
                                                    \'revisions\'
                            ) ,
                            \'show_in_nav_menus\' => true ,
                            \'taxonomies\'        => array(CUSTOM_CATEGORY_TYPE3,CUSTOM_TAG_TYPE3),
                            \'menu_position\' => 6
                    )
        );

    // Register custom taxonomy
    register_taxonomy(  CUSTOM_CATEGORY_TYPE3,
            array(  CUSTOM_POST_TYPE3   ),
            array ( 
                    "hierarchical"      => true,
                    "label"             => CUSTOM_TAXONOMY_LABEL3,
                    \'labels\'            => array(   
                                \'name\'              =>  CUSTOM_TAXONOMY_NAME3,
                                \'singular_name\'     =>  CUSTOM_TAXONOMY_SINGULAR_NAME3,
                                \'search_items\'      =>  CUSTOM_TAXONOMY_SEARCH_ITEM3,
                                \'popular_items\'     =>  CUSTOM_TAXONOMY_POPULAR_ITEM3,
                                \'all_items\'         =>  CUSTOM_TAXONOMY_ALL_ITEMS3,
                                \'parent_item\'       =>  CUSTOM_TAXONOMY_PARENT_ITEM3,
                                \'parent_item_colon\' =>  CUSTOM_TAXONOMY_PARENT_ITEM_COLON3,
                                \'edit_item\'         =>  CUSTOM_TAXONOMY_EDIT_ITEM3,
                                \'update_item\'       =>  CUSTOM_TAXONOMY_UPDATE_ITEM3,
                                \'add_new_item\'      =>  CUSTOM_TAXONOMY_ADD_NEW_ITEM3,
                                \'new_item_name\'     =>  CUSTOM_TAXONOMY_NEW_ITEM_NAME3  
                    ),
                    \'public\'            => true,
                    \'show_ui\'           => true,
                    "rewrite"           => true 
            )
    );


    register_taxonomy(CUSTOM_TAG_TYPE3,
                    array(  CUSTOM_POST_TYPE3   ),
                    array(
                        "hierarchical"      => false,
                        "label"             => CUSTOM_TAG_LABEL3,
                        \'labels\'            => array(   \'name\'              => CUSTOM_TAG_NAME3,
                        \'singular_name\'     => CUSTOM_TAG_SINGULAR_NAME3,
                        \'search_items\'      => CUSTOM_TAG_SEARCH_ITEMS3,
                        \'popular_items\'     => CUSTOM_TAG_POPULAR_ITEMS3,
                        \'all_items\'         => CUSTOM_TAG_ALL_ITEMS3,
                        \'parent_item\'       => CUSTOM_TAG_PARENT_ITEM3,
                        \'parent_item_colon\' => CUSTOM_TAG_PARENT_ITEM_COLON3,
                        \'edit_item\'         => CUSTOM_TAG_EDIT_ITEM3,
                        \'update_item\'       => CUSTOM_TAG_UPDATE_ITEM3,
                        \'add_new_item\'      => CUSTOM_TAG_ADD_NEW_ITEM3,
                        \'new_item_name\'     => CUSTOM_TAG_NEW_ITEM_NAME3    ),
                        \'public\'            => true,
                        \'show_ui\'           => true,
                        "rewrite"           => true 
                   )
    );
    //===============PRODUCT SECTION END================
    }
    ?>
如果这对你有帮助,请加上这个作为答案。您可以在两天内将其标记为已解决。帮助我们帮助您和以后的用户保持网站干净,谢谢!

结束

相关推荐

Taxonomy + post_type

我对分类法和自定义帖子类型非常迷茫。我有一个分类法->作者->我有自定义的post-type->引文(法语引文)我只想列出一个auteur(auteur=分类法)的所有引文(引号),其结构如下:www.myblogname.com/citation/auteur_name/ 或www.myblogname.com/auteur_name/citation/ 或www.myblogname.com/auteur/auteur_name/citation/ (实