Answers:
像这样:(在上面写着“投资组合”的地方,您可以将分类法注册为帖子类型
add_action( 'init', 'create_tag_taxonomies', 0 );
//create two taxonomies, genres and tags for the post type "tag"
function create_tag_taxonomies()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Tags' ),
);
register_taxonomy('tag','portfolio',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
?>
或只需添加:
'taxonomies' => array('post_tag')
此帖子类型将使用一组已注册的分类法,例如
category
或post_tag
。这可以代替register_taxonomy_for_object_type()
直接调用。自定义分类法仍需要向进行注册register_taxonomy()
。
到-file中的$args
数组functions.php
,您可以在其中创建自定义帖子类型register_post_type()
。
用这个:
add_action( 'init', 'gp_register_taxonomy_for_object_type' );
function gp_register_taxonomy_for_object_type() {
register_taxonomy_for_object_type( 'post_tag', 'portfolio' );
};
方法1(来自以上答案:https : //wordpress.stackexchange.com/a/106211/38771)
不同的帖子类型将使用与默认“帖子”类型相同的“标签”数据。
好处
一切(应该)只用一行就可以使用
您所有的标签都在CMS中的一处
缺点
方法2(从上面的答案:https : //wordpress.stackexchange.com/a/62263/38771)
不同的帖子类型使用不同的“标签”配置/数据。
好处
交易
设置更多代码
实际上,它们是一种以各种方式对各种项目进行分组的极其有效的方法。https://codex.wordpress.org/Taxonomies#Custom_Taxonomies
只需使用此代码可能会帮助您
add_action( 'init', 'create_client_tax' );
function create_client_tax() {
register_taxonomy(
'client_tag', //your tags taxonomy
'client', // Your post type
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
}