自定义分类不显示

时间:2013-04-09 作者:Angela

这里有一个片段,它似乎没有在CPT编辑屏幕中显示分类法。不确定出了什么问题,分类法和CPT都是相互注册的。

<?php
add_action(\'init\', \'create_taxonomy\');

function create_taxonomy() {
    register_taxonomy( \'farm\', array(\'farmer\', \'food\', \'recipe\'), array(
        \'label\'                                 => \'farms\',
        \'public\'                                => true,
        \'show_ui\'                               => true,
        \'show_in_nav_menus\'                     => true,
        \'show_tagcloud\'                     => true,
        \'hierarchical\'                          => true,
        \'show_admin_column\'                     => true,
        \'query_var\'                         => \'farm\',
        \'update_count_callback\' => \'\',
        \'sort\'                                  => true,
        \'labels\'                                => array(
            \'name\'                                              => __(\'Farms\'),
            \'singular_name\'             => __(\'Farm\'),
            \'menu_name\'                                     => __(\'Farm\'),
            \'all_items\'                                     => __(\'All Farms\'),
            \'edit_item\'                                     => __(\'Edit Farm\'),
            \'view_item\'                                     => __(\'View Farm\'),
            \'update_item\'                                   => __(\'Update Farm\'),
            \'add_new_item\'                              => __(\'Add New Farm\'),
            \'new_item_name\'                             => __(\'New Farm\'),
            \'search_items\'                              => __(\'Search Farms\'),
            \'popular_items\'                             => __(\'Popular Farms\'),
            \'separate_items_with_commas\'    => __(\'Separate farms by commas\'),
            \'add_or_remove_items\'                   => __(\'Add or remove farms\'),
            \'choose_from_most_used\'             => __(\'Choose from the most popular farms\'),
            \'not_found\'                                     => __(\'No farms found\')
        ),
        \'rewrite\'                               => array(
            \'slug\'                  => \'farm\',
            \'with_front\'        => false,
            \'hierarchical\'  => false,
        )
    ) );

    register_post_type( \'farmer\', array(
        \'public\'                    => true,
        \'taxonomies\'            => array( \'farm\' ),
        \'menu_position\'     => 6,
        \'capability_type\'   => \'page\',
        \'rewrite\'                   => array( \'slug\' => \'farmer\' ),
        \'supports\'              => array( \'title\', \'editor\', \'thumbnail\', \'custom-fields\' ),
        \'labels\'                    => array(
        \'name\'                              => __(\'Farmers\'),
        \'menu_name\'                     => __(\'Farmers\'),
        \'singular_name\'             => __(\'Farmer\'),
        \'add_new\'                           => __(\'Add New\'),
        \'add_new_item\'              => __(\'Add New Farmer\'),
        \'edit_item\'                     => __(\'Edit Farmer\'),
        \'new_item\'                      => __(\'New Farmer\'),
        \'all_items\'                     => __(\'All Farmers\'),
        \'view_item\'                     => __(\'View Farmer\'),
        \'search_items\'              => __(\'Search Farmers\'),
        \'not_found\'                     => __(\'No farmers found\'),
        \'not_found_in_trash\'    => __(\'No farmers found in Trash\')
        )
    ) );}
?>

1 个回复
SO网友:Nicü

我已经尝试了WordPress 3.5.1的代码安装,效果很好。

检查您正在使用的WordPress版本和变更日志,以了解您的版本是否与3.5.1中的版本不同,可能会干扰您的CPT和分类法

结束

相关推荐