admin管理员组文章数量:1291426
I have created a custom post type (products), and at the moment I have 2 custom taxonomies (lips and eyes).
I can get the archive to show up for 'products', and I can get to the URL for the archive for the categories under 'lips', but I cannot get the archive to show for the taxonomies.
I have been through every question I can find, and I have checked the answers against what I have done, but for the life of me I can't figure out what is going wrong.
I have a taxonomy template, 'taxonomy-lips.php', but it just keeps defaulting back to my front-page.php template.
Here is my code for the post type:
function my_first_post_type() {
$args = array(
'labels' => array(
'name' => 'Products',
'singular_name' => 'Product',
),
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-list-view',
'supports' => array('title', 'editor', 'thumbnail'),
'rewrite' => array('slug' => 'shop-products'),
'taxonomies' => array('lips', 'eyes'),
);
register_post_type('products', $args);
}
add_action('init', 'my_first_post_type');
And here is the code for my taxonomy:
function my_first_taxonomy()
{
$args = array(
'labels' => array(
'name' => 'Lips',
'singular_name' => 'Lips',
),
'public' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'lips'),
);
register_taxonomy('lips', array('products'), $args);
}
add_action('init', 'my_first_taxonomy');
I have reset the permalinks many times, and nothing changes.
Sorry, I know this question has been asked many times, I just can't figure out what I have done! I'm very new to all of this, so be gentle lol, I might not understand anything too complex!
I have created a custom post type (products), and at the moment I have 2 custom taxonomies (lips and eyes).
I can get the archive to show up for 'products', and I can get to the URL for the archive for the categories under 'lips', but I cannot get the archive to show for the taxonomies.
I have been through every question I can find, and I have checked the answers against what I have done, but for the life of me I can't figure out what is going wrong.
I have a taxonomy template, 'taxonomy-lips.php', but it just keeps defaulting back to my front-page.php template.
Here is my code for the post type:
function my_first_post_type() {
$args = array(
'labels' => array(
'name' => 'Products',
'singular_name' => 'Product',
),
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-list-view',
'supports' => array('title', 'editor', 'thumbnail'),
'rewrite' => array('slug' => 'shop-products'),
'taxonomies' => array('lips', 'eyes'),
);
register_post_type('products', $args);
}
add_action('init', 'my_first_post_type');
And here is the code for my taxonomy:
function my_first_taxonomy()
{
$args = array(
'labels' => array(
'name' => 'Lips',
'singular_name' => 'Lips',
),
'public' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'lips'),
);
register_taxonomy('lips', array('products'), $args);
}
add_action('init', 'my_first_taxonomy');
I have reset the permalinks many times, and nothing changes.
Sorry, I know this question has been asked many times, I just can't figure out what I have done! I'm very new to all of this, so be gentle lol, I might not understand anything too complex!
Share Improve this question edited Jun 10, 2021 at 1:30 Siobhan M asked Jun 9, 2021 at 22:52 Siobhan MSiobhan M 112 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 2I cannot get the archive to show for the taxonomies
And in the comments you said:
I can't get to example/lips
And similar to what I said here:
Taxonomies, unlike post types, do not have an archive page (which displays posts from all terms in the specific taxonomy), so it's normal if you "can't get to"
example/lips
orexample/eyes
, i.e.example/<taxonomy key>
.And secondly, taxonomy templates like
taxonomy-lips.php
actually rely upon the current taxonomy term, i.e. there has to be a term being queried in order for a taxonomy template to be used, and for functions likeis_tax()
to returntrue
. So remember, the query determines the template and not the other way round. And for exampleexample/lips/category-slug
worked (i.e.taxonomy-lips.php
was used) because there's a term being queried which is the one with the slugcategory-slug
.
So no matter how many times you flush/regenerate the rewrite rules, taxonomies simply do not have an "all-terms" archive, only specific terms in the taxonomies. See @bosco's answer here if you're interested in knowing more tech stuff about taxonomy's "archive page", which by default do not exist or not implemented in WordPress core.
I hope this answered your question, and if all you wanted to have is for the example/lips
and example/eyes
to display posts from all/any terms in the lips
/eyes
taxonomy, then an easy way is:
Create a custom Page (post of type
page
) and give it thelips
oreyes
slug.Assign a custom page template to that Page.
And then make a secondary/custom
WP_Query
query in that very template.
本文标签: Custom Taxonomy template is not recognised
版权声明:本文标题:Custom Taxonomy template is not recognised 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741514706a2382813.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
taxonomy-lips.php
? What is the URL of the page, is it likeexample/lips/category-slug
? – Sally CJ Commented Jun 10, 2021 at 0:37register_post_type()
is outside themy_first_post_type()
function.. – Sally CJ Commented Jun 10, 2021 at 0:43