_x('Books', 'post type general name'),
'singular_name' => _x('Book', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Book'),
'edit_item' => __('Edit Book'),
'new_item' => __('New Book'),
'view_item' => __('View Book'),
'search_items' => __('Search Books'),
'not_found' => __('No books found'),
'not_found_in_trash' => __('No books found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Books'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt','comments')
);
register_post_type('book',$args);
//为book添加分类
register_taxonomy('genre',array('book'), array(
'hierarchical' => true,//true为分类,false为标签
));
}
//添加过滤器,以确保课本用户更新时会显示。
add_filter('post_updated_messages', 'book_updated_messages');
function book_updated_messages( $messages ) {
global $post, $post_ID;
$messages['book'] = array(
0 => '', // 未使用。信息开始在索引1。
1 => sprintf( __('Book updated. View book'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Book updated.'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Book published. View book'), esc_url( get_permalink($post_ID) ) ),
7 => __('Book saved.'),
8 => sprintf( __('Book submitted. Preview book'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Book scheduled for: %1$s. Preview book'),
// 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( __('Book draft updated. Preview book'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
//显示图书上下文帮助
add_action( 'contextual_help', 'add_help_text', 10, 3 );
function add_help_text($contextual_help, $screen_id, $screen) {
//$contextual_help .= var_dump($screen); // use this to help determine $screen->id
if ('book' == $screen->id ) {
$contextual_help =
'' . __('Things to remember when adding or editing a book:') . '
' .
'' .
'- ' . __('Specify the correct genre such as Mystery, or Historic.') . '
' .
'- ' . __('Specify the correct writer of the book. Remember that the Author module refers to you, the author of this book review.') . '
' .
'
' .
'' . __('If you want to schedule the book review to be published in the future:') . '
' .
'' .
'- ' . __('Under the Publish module, click on the Edit link next to Publish.') . '
' .
'- ' . __('Change the date to the date to actual publish this article, then click on Ok.') . '
' .
'
' .
'' . __('For more information:') . '
' .
'' . __('Edit Posts Documentation') . '
' .
'' . __('Support Forums') . '
' ;
} elseif ( 'edit-book' == $screen->id ) {
$contextual_help =
'' . __('This is the help screen displaying the table of books blah blah blah.') . '
' ;
}
return $contextual_help;
}
?>
创建或修改一个文章类型。该函数不能在init动作之前使用。
用法
参数
(string) (必选) 文章类型。(最多20个字符)
默认值: 空
(string) (可选) 是新类型的别名标记
_x('Add New', 'product');
默认情况下该数组有7个键可以接受参数:
也有其他七个原始的功能不是直接用在核心,但在map_meta_cap()。上述三个元功能,将它们转换成一个或多个原始的功能,就必须根据上下文对用户或角色的检查。这些额外的功能只用于map_meta_cap()。因此,如果该类型已经注册,“map_meta_cap” 默认值将为 true,否则默认为false。
(boolean) (可选) 是否此类型支持层级和允许被指定为父级
(array) (可选) 此类型支持的已注册分类法类型数组,如 category
或 post_tag
。 雷同register_taxonomy_for_object_type() 。分类法可以使用 register_taxonomy()来注册。
$args array
注册一个文章类型叫 "book"的范例,包括提供上下文帮助:
原文地址:http://www.xggxgg.com/392.html