我已注册分类:
$taxonomySetup = [
\'label\' => __(\'Products catalog\'),
\'has_archive\' => false,
\'hierarchical\' => true,
\'rewrite\' => [
\'slug\' => __(\'catalog\'),
\'hierarchical\' => true,
\'with_front\' => true
],
];
register_taxonomy(\'products\', [\'product\'], $taxonomySetup);
add_action(\'init\', \'addTaxonomiesToPages\');
function addTaxonomiesToPages() {
register_taxonomy_for_object_type(\'products\', \'product\');
}
链接到CPT:
register_post_type(\'product\', [
\'labels\' => [
// labels definitions
],
\'public\' => true,
\'has_archive\' => true,
\'menu_icon\' => \'dashicons-archive\',
\'show_in_nav_menus\' => true,
\'taxonomies\' => [\'products\'],
\'publicly_queryable\' => false,
\'rewrite\' => [
\'pages\' => true,
],
\'supports\' => [
// supported items
],
]);
现在,我有了类别(对于此分类法)结构和结果:
http://example.com/catalog
- Not Foundhttp://example.com/catalog/subcategory-1
- taxonomy.phphttp://example.com/catalog/subcategory-1/subcategory-2
- taxonomy.phphttp://example.com/catalog/subcategory-1/subcategory-2/subcategory-3
- taxonomy.phphttp://example.com/catalog/subcategory-1/subcategory-2/subcategory-3/subcategory-4
- taxonomy.php
我为它创建了许多文件:
taxonomy.php
taxonomy-products.php
taxonomy-product.php
taxonomy-catalog.php
为什么它总是加载基本分类法模板,而对于主目录,它总是呈现
404
错误
顺便问一下,我如何控制应该为子类别加载哪个模板(我说的是子级别,而不是命名)?