我会尽量详细地回答这个问题,但考虑到你已经掌握了基本知识,请尽量简短。假设我们的自定义post类型1连接到分类法类型1。让我们称它们为“控制台”(自定义帖子类型)和“品牌”(分类法)。您想要实现:http://example.com/console/brands/sony/Steps:首先注册分类法并将其附加到自定义post类型控制台
$labels = array(
\'name\' => \'Brands\',
\'singular_name\' => \'Brand\',
\'search_items\' => \'Search Brands\',
\'popular_items\' => \'Popular Brands\',
\'all_items\' => \'All Brands\',
\'parent_item\' => \'Parent Brand\',
\'edit_item\' => \'Edit Brand\',
\'update_item\' => \'Update Brand\',
\'add_new_item\' => \'Add New Brand\',
\'new_item_name\' => \'New Brand\',
\'separate_items_with_commas\' => \'Separate Brands with commas\',
\'add_or_remove_items\' => \'Add or remove Brands\',
\'choose_from_most_used\' => \'Choose from most used Brands\'
);
$args = array(
\'label\' => \'Brands\',
\'labels\' => $labels,
\'public\' => true,
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'args\' => array( \'orderby\' => \'term_order\' ),
\'rewrite\' => array( \'slug\' => \'consoles/brands\', \'with_front\' => false ),
\'query_var\' => true
);
register_taxonomy( \'brands\', \'consoles\', $args );
请注意,$args数组中的重写键。该值告诉WordPress slug在我们的自定义分类法中使用。我们不希望它以默认为true的WordPress permalink前端基作为前缀,我们希望slug包含我们自定义的Post类型重写slug。
Step Two:现在创建自定义帖子类型。我并不是在写全部代码,但请记住这里的重要参数是“重写”
\'rewrite\' => array( \'slug\' => \'consoles\', \'with_front\' => false ),
visit your Settings > Permalinks options screen in the WordPress admin to ensure your new permalinks are picked up
对第二个自定义帖子类型和分类重复步骤2.:)干杯PS:您需要定义has\\u存档密钥才能拥有存档页面。