自定义发布类型分类法和消息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义发布类型分类法和消息相关的知识,希望对你有一定的参考价值。
This gives the code for creating a custom post type with all the necessary labels and even custom message support, and it gives the code for a custom taxonomy with that post type.
// 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( 'Portfolio Galleries', 'post type general name' ), // Tip: _x('') is used for localization 'singular_name' => _x( 'Portfolio Gallery', 'post type singular name' ), 'add_new' => _x( 'Add New', 'Portfolio Gallery' ), 'add_new_item' => __( 'Add New Portfolio Gallery' ), 'edit_item' => __( 'Edit Portfolio Gallery' ), 'new_item' => __( 'New Portfolio Gallery' ), 'view_item' => __( 'View Portfolio Gallery' ), 'search_items' => __( 'Search Portfolio Galleries' ), 'not_found' => __( 'No Portfolio Galleries found' ), 'not_found_in_trash' => __( 'No Portfolio Galleries found in Trash' ), 'parent_item_colon' => '' ); // Create an array for the $args 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => true, 'menu_position' => null, ); register_post_type( 'portfolio-gallery', $args ); /* Register it and move on */ } //add a custom message to the post message function add_filter('post_updated_messages', 'gallery_updated_messages'); function gallery_updated_messages( $messages ) { 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __('Gallery updated. <a href="%s">View Gallery</a>'), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Gallery updated.'), /* translators: %s: date and time of the revision */ 6 => sprintf( __('Gallery published. <a href="%s">View Gallery</a>'), esc_url( get_permalink($post_ID) ) ), 7 => __('Gallery saved.'), 8 => sprintf( __('Gallery submitted. <a target="_blank" href="%s">Preview Gallery</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('Gallery scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Gallery</a>'), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('Gallery draft updated. <a target="_blank" href="%s">Preview Gallery</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); return $messages; } // hook into the init action and call create_gallery_taxonomies() when it fires add_action( 'init', 'create_gallery_taxonomies', 0 ); function create_gallery_taxonomies() { // Add new taxonomy, hierarchical 'name' => _x( 'Categories', 'taxonomy general name' ), 'singular_name' => _x( 'Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Categories' ), 'popular_items' => __( 'Popular Categories' ), 'all_items' => __( 'All Categories' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Category' ), 'update_item' => __( 'Update Category' ), 'add_new_item' => __( 'Add New Category' ), 'new_item_name' => __( 'New Category Name' ), 'separate_items_with_commas' => __( 'Separate categories with commas' ), 'add_or_remove_items' => __( 'Add or remove categories' ), 'choose_from_most_used' => __( 'Choose from the most used categories' ) ); 'hierarchical' => true, 'labels' => $labels, /* NOTICE: the $labels variable here */ 'show_ui' => true, 'query_var' => true, )); }
以上是关于自定义发布类型分类法和消息的主要内容,如果未能解决你的问题,请参考以下文章