我已注册自定义帖子类型city
有2种分类法city_categories
和cities
. 但wordpress正在存档。php而不是archive city。php,不明白我错在哪里了。只有创建分类城市时,它才有效。php,然后是城市分类法。php。我怎样才能让它直接进入存档城市。php
register_post_type( \'city\',
array(
\'labels\' =>
array(
\'name\' => \'City Guides\',
\'singular_name\' => \'City Guides\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New retailer\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit retailer\',
\'new_item\' => \'New retailer\',
\'view\' => \'View\',
\'view_item\' => \'View retailer\',
\'search_items\' => \'Search retailers\',
\'not_found\' => \'No retailer found\',
\'not_found_in_trash\' => \'No Shop retailer in Trash\',
\'parent\' => \'Parent retailer\'
),
\'public\' => true,
\'menu_position\' => 6,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'has_archive\' => true,
\'taxonomies\' => array(\'city_categories\'),
\'can_export\' => true,
\'rewrite\' => array(\'slug\'=>\'travel\')
)
);
$args = array(
\'labels\' => $labels, // defined correctly, shortened the code
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'rewrite\' => true,
\'query_var\' => true
);
register_taxonomy( \'city_categories\', array(\'city\'), $args );
$args = array(
\'labels\' => $labels, // defined correctly, shortened the code
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'rewrite\' => true,
\'query_var\' => true,
\'sort\' => true
);
register_taxonomy( \'cities\', array(\'city\'), $args );
SO网友:cybmeta
我已经测试了您的代码,如果您在init
行动挂钩。在您的代码中,我没有看到注册post类型的操作挂钩。Cna你试试这个?(请记住在更新代码后刷新rewirte规则。请注意,我删除了未定义的变量$labels
在$args
分类法数组):
add_action(\'init\', \'cyb_register_post_type_and_taxonomies\');
function cyb_register_post_type_and_taxonomies() {
register_post_type( \'city\',
array(
\'labels\' =>
array(
\'name\' => \'City Guides\',
\'singular_name\' => \'City Guides\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New retailer\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit retailer\',
\'new_item\' => \'New retailer\',
\'view\' => \'View\',
\'view_item\' => \'View retailer\',
\'search_items\' => \'Search retailers\',
\'not_found\' => \'No retailer found\',
\'not_found_in_trash\' => \'No Shop retailer in Trash\',
\'parent\' => \'Parent retailer\'
),
\'public\' => true,
\'menu_position\' => 6,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'has_archive\' => true,
\'taxonomies\' => array(\'city_categories\'),
\'can_export\' => true,
\'rewrite\' => array(\'slug\'=>\'travel\')
)
);
$args = array(
\'labels\' => array(),
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'rewrite\' => true,
\'query_var\' => true
);
register_taxonomy( \'city_categories\', array(\'city\'), $args );
$args = array(
\'labels\' => array(), // defined correctly, shortened the code
\'public\' => true,
\'show_in_nav_menus\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => true,
\'show_admin_column\' => true,
\'hierarchical\' => true,
\'rewrite\' => true,
\'query_var\' => true,
\'sort\' => true
);
register_taxonomy( \'cities\', array(\'city\'), $args );
}