我想显示分类法模板时遇到问题
我已经为我的自定义帖子类型“Project”创建了一个自定义分类“Location”。此外,我还为其创建了以下模板:
taxonomy-{taxonomy_name}-{term}.php
taxonomy-{taxonomy_name}.php
taxonomy.php
它们都不起作用。。。我刚得到我的存档{post\\u type}。php在所有情况下。
我的目标URL是:
mywebsite.com/holliday/united-kingdom/
(位置分类法)
mywebsite.com/holliday/united-kingdom/london
(位置分类子项)
在创建分类法时,我本应该把事情搞砸或遗漏一些东西,但我做不好。
这是我的代码(register post type和register taxonomy):
// Register Post Type (Holliday)
$capability = \'publish_posts\';
$cpt_args = array(
\'menu_icon\' => \'dashicons-groups\',
\'labels\' => array(
\'name\' => __( \'Holliday\', \'mon-plugin\' ),
\'singular_name\' => __( \'Holliday\', \'mon-plugin\' ),
\'add_new\' => __( \'Add Holliday\', \'mon-plugin\' ),
\'add_new_item\' => __( \'Add Holliday\', \'mon-plugin\' ),
\'edit\' => __( \'Edit\', \'mon-plugin\' ),
\'edit_item\' => __( \'Edit Holliday\', \'mon-plugin\' ),
\'new_item\' => __( \'New Holliday\', \'mon-plugin\' ),
\'view\' => __( \'View Holliday\', \'mon-plugin\' ),
\'view_item\' => __( \'View Holliday\', \'mon-plugin\' ),
\'search_items\' => __( \'Search Holliday\', \'mon-plugin\' ),
\'not_found\' => __( \'No Holliday found\', \'mon-plugin\' ),
\'not_found_in_trash\'=> __( \'No Holliday found in Trash\', \'mon-plugin\' ),
\'parent\' => __( \'Parent Holliday\', \'mon-plugin\' ),
),
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(
\'slug\' => \'holliday/%my_project_location%\',
),
\'supports\' => array(\'title\', \'custom-fields\', \'excerpt\', \'editor\', \'author\', \'thumbnail\', \'comments\'),
\'capabilities\' => array(
\'publish_posts\' => $capability,
\'edit_posts\' => $capability,
\'edit_others_posts\' => $capability,
\'delete_posts\' => $capability,
\'delete_others_posts\'=> $capability,
\'read_private_posts\'=> $capability,
\'edit_post\' => $capability,
\'delete_post\' => $capability,
\'read_post\' => $capability
),
);
register_post_type( \'my_project\', $cpt_args );
// Register Taxonomy (Location)
$cats_args = array(
\'labels\' => array(
\'name\' => _x( \'Project Location\', \'mon-plugin\' ),
\'singular_name\' => _x( \'Location\', \'mon-plugin\' ),
\'search_items\' => __( \'Search Location\', \'mon-plugin\' ),
\'all_items\' => __( \'All Location\', \'mon-plugin\' ),
\'parent_item\' => __( \'Parent Location\', \'mon-plugin\' ),
\'parent_item_colon\' => __( \'Parent Location:\', \'mon-plugin\' ),
\'edit_item\' => __( \'Edit Location\', \'mon-plugin\' ),
\'update_item\' => __( \'Update Location\', \'mon-plugin\' ),
\'add_new_item\' => __( \'Add New Location\', \'mon-plugin\' ),
\'new_item_name\' => __( \'New Location Name\', \'mon-plugin\' ),
\'menu_name\' => __( \'Location\', \'mon-plugin\' ),
),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'has_archive\' => true,
\'rewrite\' => array(
\'slug\' => \'holliday\',
\'hierarchical\' => true
)
);
register_taxonomy( \'my_project_location\', \'my_project\', $cats_args );
编辑:
如果我将分类法slug更改为其他内容,我会使分类法模板正常工作
示例:
taxonomy slug => "location"
mywebsite.com/location/united-kingdom/ => Taxonomy template working !
但我希望我的分类法与我的自定义帖子类型配合使用。访问时获取分类法模板
mywebsite.com/{custom-post-type}/{taxonomy}/
<但是这个给我
archive-{custom-post-type}.php
改为文件。
遵循Template Hierarchy 我希望Wordpress在归档模板之前为我找到分类模板。
我有什么遗漏吗<谢谢你的帮助。