wordpress - 我可以为 wordpress 创建第二个自定义标签系统吗?
问题描述
我需要在 Wordpress 中有一个主要和次要标记系统,但我发现很难创建第二个自定义标记系统,而且似乎没有太多关于这方面的教程。
有谁知道实现这一目标的方法?
感谢您的时间和建议!
我需要一些不同于自定义分类的东西,我需要它是标签。
解决方案
如果我理解正确,您可以根据需要创建任意数量的自定义标签。这是创建两个自定义标签的示例:
// Register Custom Taxonomy
function custom_tags1() {
$labels = array(
'name' => _x( 'Custom Tags 1', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Custom Tags 1', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Custom Tags 1', 'text_domain' ),
'all_items' => __( 'All Custom Tags 1', 'text_domain' ),
'parent_item' => __( 'Parent Tag', 'text_domain' ),
'parent_item_colon' => __( 'Parent Tag:', 'text_domain' ),
'new_item_name' => __( 'New Tag Name', 'text_domain' ),
'add_new_item' => __( 'Add New Tag', 'text_domain' ),
'edit_item' => __( 'Edit Tag', 'text_domain' ),
'update_item' => __( 'Update Tag', 'text_domain' ),
'view_item' => __( 'View Tag', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate Tags with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove Tags', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Tags', 'text_domain' ),
'search_items' => __( 'Search Tags', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No Tags', 'text_domain' ),
'items_list' => __( 'Tags list', 'text_domain' ),
'items_list_navigation' => __( 'Tags list navigation', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'custom_tags_1', array( 'post' ), $args );
}
add_action( 'init', 'custom_tags1', 0 );
// Register Custom Taxonomy
function custom_tags2() {
$labels = array(
'name' => _x( 'Custom Tags 2', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Custom Tags 2', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Custom Tags 2', 'text_domain' ),
'all_items' => __( 'All Custom Tags 2', 'text_domain' ),
'parent_item' => __( 'Parent Tag', 'text_domain' ),
'parent_item_colon' => __( 'Parent Tag:', 'text_domain' ),
'new_item_name' => __( 'New Tag Name', 'text_domain' ),
'add_new_item' => __( 'Add New Tag', 'text_domain' ),
'edit_item' => __( 'Edit Tag', 'text_domain' ),
'update_item' => __( 'Update Tag', 'text_domain' ),
'view_item' => __( 'View Tag', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate Tags with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove Tags', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Tags', 'text_domain' ),
'search_items' => __( 'Search Tags', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No Tags', 'text_domain' ),
'items_list' => __( 'Tags list', 'text_domain' ),
'items_list_navigation' => __( 'Tags list navigation', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'custom_tags_2', array( 'post' ), $args );
}
add_action( 'init', 'custom_tags2', 0 );
推荐阅读
- caching - CUDA 对全局内存的低效访问模式
- swift - 如何将 DateFormatter 烘焙到 Swift 结构中,这样我就不需要告诉 JSONDecoder?
- python - Python websocket没有获取所有数据
- apache-spark - 如何在 pyspark 管道中添加 UDF?
- mysql - 没有外键如何引用?
- windows - 在for循环中获取找到的文件的路径
- php - php中的PDO是一个类还是类的集合?或者它到底是什么?
- hadoop - 错误:无法找到或加载主类 org.apache.hadoop.hdfs.server.datanode.DataNode
- angular - Angular 5:如何路由嵌套的延迟加载模块?
- javascript - 使用 fetch 和 get 方法调用 API