Wordpress注册自定义Post类型和自定义分类法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress注册自定义Post类型和自定义分类法相关的知识,希望对你有一定的参考价值。
Register a Custom Post Type and a Custom Taxonomy in Wordpress
/** -------------- ADD CUSTOM POST TYPES ----------------- **/ // The register_post_type() function is not to be used before the 'init'. add_action( 'init', 'my_custom_init' ); /* Here's how to create your customized labels */ function my_custom_init() { 'name' => _x( 'Case Studies', 'post type general name' ), // Tip: _x('') is used for localization 'singular_name' => _x( 'Case Study', 'post type singular name' ), 'add_new' => _x( 'Add New', 'book' ), 'add_new_item' => __( 'Add New Case Study' ), 'edit_item' => __( 'Edit Case Study' ), 'new_item' => __( 'New Case Study' ), 'view_item' => __( 'View Case Study' ), 'search_items' => __( 'Search Case Studies' ), 'not_found' => __( 'No Case Studies found' ), 'not_found_in_trash' => __( 'No Case Studies found in Trash' ), 'parent_item_colon' => '' ); // Create an array for the $args 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => true, 'menu_position' => null, 'has_archive' => true, 'rewrite' => true, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes' ) ); register_post_type( 'case-studies', $args ); /* Register it and move on */ } /** -------------- REGISTER CUSTOM TAXONOMIES ----------------- **/ //hook into the init action and call create_book_taxonomies when it fires add_action( 'init', 'create_casestudies_taxonomies', 0 ); //create two taxonomies, genres and writers for the post type "book" function create_casestudies_taxonomies() { // Add new taxonomy, make it hierarchical (like categories) 'name' => _x( 'Project Type', 'taxonomy general name' ), 'singular_name' => _x( 'Project Type', 'taxonomy singular name' ), 'search_items' => __( 'Search Project Types' ), 'all_items' => __( 'All Project Types' ), 'parent_item' => __( 'Parent Project Type' ), 'parent_item_colon' => __( 'Parent Project Type:' ), 'edit_item' => __( 'Edit Project Type' ), 'update_item' => __( 'Update Project Type' ), 'add_new_item' => __( 'Add New Project Type' ), 'new_item_name' => __( 'New Project Type Name' ), 'menu_name' => __( 'Project Type' ), ); 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, )); }
以上是关于Wordpress注册自定义Post类型和自定义分类法的主要内容,如果未能解决你的问题,请参考以下文章