我有一个名为“products”的自定义帖子类型,它有一个称为“collections”的自定义分类法
这就是我注册分类法的方式。
$productTaxonomyArgs = [
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_admin_column\' => true,
\'description\' => __(\'Product category\', \'byronposttypes\'),
\'hierarchical\' => true,
\'rewrite\' => [
\'slug\' => __(\'collections\', \'byronposttypes\'),
\'with_front\' => true,
\'hierarchical\' => true,
\'ep_mask\' => EP_CATEGORIES
],
];
register_taxonomy(\'collections\', \'products\', $productTaxonomyArgs);
register_taxonomy_for_object_type(\'collections\', \'products\');
我创建了一个名为taxonomy collections的分类法模板。php。
<?php
get_header();
$post = null;
echo \'<h1>taxonomy-collections.php</h1>\'; //Echo this to make sure the template works.
if (have_posts()) {
while (have_posts()) { //rest of the code
当我导航到
/collections/lifestyle (生活方式是分类术语之一)
<title> 是“生活方式存档-[sitename]”,因此Wordpress确实将url识别为分类术语存档。问题是,它甚至没有回声
<h1>taxonomy-collections.php</h1> 转到页面。这让我认为
taxonomy-collections.php Wordpress无法识别<你知道我做错了什么吗?非常感谢您的阅读和帮助<我发现Wordpress正在退回索引。php。但是
is_tax(); 退货
true. 似乎没有一个特定于分类法的模板可以工作(
taxonomy.php,
taxonomy-collection.php 和
taxonomy-collection-lifestyle.php), 甚至没有
archive.php 将起作用。
SO网友:Harry
试试这个代码,它对我有用。。
function add_collection_taxonomies() {
$productTaxonomyArgs = array(
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_admin_column\' => true,
\'description\' => __(\'Product category\', \'byronposttypes\'),
\'hierarchical\' => true,
\'rewrite\' => array(
\'slug\' => __(\'collections\', \'byronposttypes\'),
\'with_front\' => true,
\'hierarchical\' => true,
\'ep_mask\' => EP_CATEGORIES
),
);
register_taxonomy_for_object_type(\'collections\', \'products\');
register_taxonomy(\'collections\', \'product\', $productTaxonomyArgs);