有没有办法让 wordpress post 类别功能正常但不可见?
Is there a way to have a wordpress post category that is functional but not visible?
我想在 post 和 post 中显示类别,但我也想使用有助于组织网站周围 post 显示的类别但不可见。
例如,一个 'featured' 类别可能适用于不相关类别中的一系列 post,但它们是在特定区域显示的最有价值的 post .我不想向用户显示类别 'featured'。
使用自定义分类法instead.One可以指定它们不是public,但仍然使用它们进行查询和分组。 https://developer.wordpress.org/reference/functions/register_taxonomy/
您正在查看自定义分类法。自定义分类法可以应用于多个帖子。您可以使用参数控制它们的行为。
CT 看起来有点像,并在您的 function.php
文件中声明
<?php
/**
* Add CT to CPT
*/
add_action( 'init', 'custom_taxonomy_langues' );
function custom_taxonomy_langues() {
$taxonomy = '_related_CPT_goes_here';
$singular = '_CT_singular_name';
$plural = '_CT_plural_name';
$labels = array(
'name' => $plural,
'singular_name' => $singular,
);
$args = array(
'labels' => $labels,
'description' => '',
'hierarchical' => 1,
'public' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => array( 'slug' => strtolower( $plural ), 'hierarchical' => 1 ),
);
register_taxonomy( strtolower( $plural ), strtolower( $taxonomy ), $args );
}; ?>
如您所见,您几乎可以控制与行为有关的所有方面,您可以查询它们吗,它们是否有存档页面,您是否希望它们显示在管理员 ui 中,如果是的话在哪里。 ..等等
已经有一堆文章了,你可以看看这篇https://wordpress.stackexchange.com/questions/92430/can-multiple-custom-post-types-share-a-custom-taxonomy关于将多个 CPT 连接到单个 CT 的文章。
我想在 post 和 post 中显示类别,但我也想使用有助于组织网站周围 post 显示的类别但不可见。
例如,一个 'featured' 类别可能适用于不相关类别中的一系列 post,但它们是在特定区域显示的最有价值的 post .我不想向用户显示类别 'featured'。
使用自定义分类法instead.One可以指定它们不是public,但仍然使用它们进行查询和分组。 https://developer.wordpress.org/reference/functions/register_taxonomy/
您正在查看自定义分类法。自定义分类法可以应用于多个帖子。您可以使用参数控制它们的行为。
CT 看起来有点像,并在您的 function.php
文件中声明
<?php
/**
* Add CT to CPT
*/
add_action( 'init', 'custom_taxonomy_langues' );
function custom_taxonomy_langues() {
$taxonomy = '_related_CPT_goes_here';
$singular = '_CT_singular_name';
$plural = '_CT_plural_name';
$labels = array(
'name' => $plural,
'singular_name' => $singular,
);
$args = array(
'labels' => $labels,
'description' => '',
'hierarchical' => 1,
'public' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => array( 'slug' => strtolower( $plural ), 'hierarchical' => 1 ),
);
register_taxonomy( strtolower( $plural ), strtolower( $taxonomy ), $args );
}; ?>
如您所见,您几乎可以控制与行为有关的所有方面,您可以查询它们吗,它们是否有存档页面,您是否希望它们显示在管理员 ui 中,如果是的话在哪里。 ..等等
已经有一堆文章了,你可以看看这篇https://wordpress.stackexchange.com/questions/92430/can-multiple-custom-post-types-share-a-custom-taxonomy关于将多个 CPT 连接到单个 CT 的文章。