简体   繁体   English

类别分类与默认类别帖子

[英]Category Taxonomy vs default Category post

I have a trivial question about Taxonomy, and it's confusing me a lot.我有一个关于分类学的琐碎问题,这让我很困惑。 I've read dozen of posts, blogs I don't want to install a plugin to manage CTP's url cuz I would like to understand this before.我已经阅读了几十篇文章,博客我不想安装插件来管理 CTP 的 url 因为我以前想了解这一点。

After creating a CPT, if I register categories on this CPT, does WP manage those categories as a "category" or like a taxonomy called "category"?创建 CPT 后,如果我在此 CPT 上注册类别,WP 是否将这些类别管理为“类别”或类似于称为“类别”的分类法?

-> Do you use "taxonomy-cpt_name.php" or "archives_cpt_name-tax_name.php" (or "category-cpt_name-tax_name")? -> 你使用“taxonomy-cpt_name.php”还是“archives_cpt_name-tax_name.php”(或“category-cpt_name-tax_name”)?

Mine actually use category.php for now.我现在实际使用的是category.php

What's a custom taxonomy什么是自定义分类法

A taxonomy within WordPress is a way of grouping posts together based on a select number of relationships. WordPress 中的分类法是一种基于 select 关系数将帖子分组在一起的方法。 By default, a standard post will have two taxonomy types called Categories and Tags which are a handy way of ensuring related content on your website is easy for visitors to find.默认情况下,标准帖子将有两种分类类型,称为类别和标签,这是确保访问者轻松找到网站上相关内容的便捷方式。 These two types of taxonomies are included in WordPress by default, but just like any other taxonomy, can be removed or changed and you can even add more if you like.这两种分类法默认包含在 WordPress 中,但就像任何其他分类法一样,可以删除或更改,您甚至可以根据需要添加更多。

A custom taxonomy is just a classification tool you can add to a post/page... It can either be acting as a tag , with no hierarchical order (eg: terms childrens) or as a category , with in this case a hierarchical order using the hierarchical argument upon registration .自定义分类法只是您可以添加到帖子/页面的分类工具......它可以充当tag ,没有分层顺序(例如:术语儿童)或作为category ,在这种情况下是分层顺序在注册时使用hierarchical参数

<?php // ...
'hierarchical' => false, // ... registered as tag
'hierarchical' => true, // ... registered as category
// ...
?>

hierarchical (boolean) (optional) Is this taxonomy hierarchical (have descendants) like categories or not hierarchical like tags. hierarchical (布尔)(可选)此分类是分层的(有后代)类似类别还是不分层的标签。 Default: false.默认值:假。


Reserved Terms保留条款

You wouldn't be able to use category has the handle, has some terms are reserved for Wordpress itself.您将无法使用category有句柄,有一些术语是为 Wordpress 本身保留的。

Avoiding the following reserved terms is particularly important if you are passing the term through the $_GET or $_POST array.如果您通过 $_GET 或 $_POST 数组传递术语,则避免以下保留术语尤为重要。 Doing so can cause WordPress to respond with a 404 error without any other hint or explanation.这样做可能会导致 WordPress 响应 404 错误而没有任何其他提示或解释。

  • attachment , attachment_id attachmentattachment_id

  • author , author_name author , author_name

  • cat , category , category__and , category__in , category__not_in , category_name , link_category , catcategorycategory__and __and, category__in __in, category_name link_categorycategory__not_in名称,链接类别,

  • taxonomy , term , terms taxonomy , term , terms

  • tag , tag__and , tag__in , tag__not_in , tag_id , tag_slug__and , tag_slug__in tag , 标签tag__and , tag__in , tag__not_in , tag_id , tag_slug__and , tag_slug__in

  • comments_per_page , comments_popup , withcomments , withoutcomments comments_per_page , comments_popup , withcomments , withoutcomments

  • custom , customize_messenger_channel , customized customcustomize_messenger_channelcustomized

  • nav_menu , name , fields , embed , title , sentence nav_menunamefieldsembedtitlesentence

  • calendar , day , hour , m , minute , monthnum , year , second calendar , day , hour , m , minute , monthnum , year , second

  • perm , order , orderby , offset , preview , s , search , debug , more , nopaging perm , order , orderby , offset , preview , s , search , debug , more , nopaging

  • p , page , page_id , paged , pagename , cpage p , page , page_id , paged , pagename , cpage

  • post , post__in , post__not_in , post_format , post_mime_type , post_status , post_tag , post_type , posts , posts_per_archive_page , posts_per_page , subpost , subpost_id , showposts post , post__in , post__not_in , post_format , post_mime_type , post_status , post_tag , post_type , posts , posts_per_archive_page , posts_per_page , subpost , subpost_id , showposts

  • robots , error , exact , feed , nonce , pb , status , static , theme , type , types , tb , w robotserrorexactfeednoncepbstatusstaticthemetypetypestbw

Up-to-date list @ https://developer.wordpress.org/reference/functions/register_taxonomy/#reserved-terms最新列表@ https://developer.wordpress.org/reference/functions/register_taxonomy/#reserved-terms


Naming your custom taxonomy命名您的自定义分类

Your custom taxonomy can be anything really, beside what's on the reserved terms list.除了保留条款列表中的内容之外,您的自定义分类实际上可以是任何东西。 If you really want your custom taxonomy to be called "category" I would suggest you use synonyms ( set , listing , ...) or underscores ( cpt_category , ...)如果您真的希望您的自定义分类法被称为“类别”,我建议您使用同义词( setlisting ,...)或下划线( cpt_category ,...)


Sharing your custom taxonomy共享您的自定义分类

Default taxonomies ( category , tags ...) or custom taxonomies can be shared.可以共享默认分类法( categorytags ...)或自定义分类法。 You could use for example the default taxonomies category and tags in your custom post type.例如,您可以在自定义帖子类型中使用默认分类法categorytags

While using register_post_type you can specify which taxonomies to use using the taxonomies argument.使用register_post_type时,您可以使用taxonomies参数指定要使用的分类法。

<?php / ...
'taxonomies' => array( 'category', 'tag', ),
/ ...
?>

Thank you for replying,谢谢你的回复,

One great thing: I understand you can't use 'category' for a Tax.一件好事:我知道您不能将“类别”用于税收。 name, I couldn't find the affirmation or not somewhere.名字,我在某处找不到肯定或没有。

Means 'category' works in CPT as in posts (width category.php)?意味着“类别”在 CPT 中的工作方式与在帖子中一样(宽度 category.php)? ok.好的。 But it seems on WP hierarchy, I can't use a "category-{cpt_name}.php" in order to filter the custom posts in category template (to have a category with just the posts of the CPT).但似乎在 WP 层次结构中,我不能使用“category-{cpt_name}.php”来过滤类别模板中的自定义帖子(拥有一个仅包含 CPT 帖子的类别)。

So I will probably create a hierarchical taxonomy called "cptName_category" in order to use a "taxonomy-{name}.php" template.因此,我可能会创建一个名为“cptName_category”的分层分类法,以便使用“taxonomy-{name}.php”模板。 Subsidiary question 1: why category-{cpt_name}.php has not be integreted in wp?附属问题1:wp中为什么没有集成category-{cpt_name}.php? ->for sure, the reason is logic:) (as we can see on hierarchy). ->当然,原因是逻辑:)(正如我们在层次结构中看到的那样)。

++Thank you a lot, Nicolas. ++非常感谢,尼古拉斯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM