This 来自WordPress网站,我在文档中找不到我的答案。当我发布register_post_type
, 它如何知道要使用哪个函数?我知道init
已使用自定义挂钩填充操作codex_book_init
, 但当我看register\\u post\\u类型时。它只有“书”:
add_action( \'init\', \'codex_book_init\' );
register_post_type( \'book\', $args );
这是如何工作的?不询问所有
$args
, 只有与此问题相关的一个(s)。
add_action( \'init\', \'codex_book_init\' );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {
$labels = array(
\'name\' => _x( \'Books\', \'post type general name\', \'your-plugin-textdomain\' ),
\'singular_name\' => _x( \'Book\', \'post type singular name\', \'your-plugin-textdomain\' ),
\'menu_name\' => _x( \'Books\', \'admin menu\', \'your-plugin-textdomain\' ),
\'name_admin_bar\' => _x( \'Book\', \'add new on admin bar\', \'your-plugin-textdomain\' ),
\'add_new\' => _x( \'Add New\', \'book\', \'your-plugin-textdomain\' ),
\'add_new_item\' => __( \'Add New Book\', \'your-plugin-textdomain\' ),
\'new_item\' => __( \'New Book\', \'your-plugin-textdomain\' ),
\'edit_item\' => __( \'Edit Book\', \'your-plugin-textdomain\' ),
\'view_item\' => __( \'View Book\', \'your-plugin-textdomain\' ),
\'all_items\' => __( \'All Books\', \'your-plugin-textdomain\' ),
\'search_items\' => __( \'Search Books\', \'your-plugin-textdomain\' ),
\'parent_item_colon\' => __( \'Parent Books:\', \'your-plugin-textdomain\' ),
\'not_found\' => __( \'No books found.\', \'your-plugin-textdomain\' ),
\'not_found_in_trash\' => __( \'No books found in Trash.\', \'your-plugin-textdomain\' )
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'book\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'book\', $args );
}
SO网友:Joey Yax
book是您正在注册的帖子类型的名称。然后它引用$args
数组定义自定义帖子类型的属性。它可以这么简单地写:
add_action( \'init\', \'codex_book_init\' );
function codex_book_init() {
register_post_type(
\'book\',
array( // Arguments
\'labels\' => array(
\'name\' => _x( \'Books\', \'post type general name\', \'your-plugin-textdomain\' ),
\'singular_name\' => _x( \'Book\', \'post type singular name\', \'your-plugin-textdomain\' ),
\'menu_name\' => _x( \'Books\', \'admin menu\', \'your-plugin-textdomain\' ),
\'name_admin_bar\' => _x( \'Book\', \'add new on admin bar\', \'your-plugin-textdomain\' ),
\'add_new\' => _x( \'Add New\', \'book\', \'your-plugin-textdomain\' ),
\'add_new_item\' => __( \'Add New Book\', \'your-plugin-textdomain\' ),
\'new_item\' => __( \'New Book\', \'your-plugin-textdomain\' ),
\'edit_item\' => __( \'Edit Book\', \'your-plugin-textdomain\' ),
\'view_item\' => __( \'View Book\', \'your-plugin-textdomain\' ),
\'all_items\' => __( \'All Books\', \'your-plugin-textdomain\' ),
\'search_items\' => __( \'Search Books\', \'your-plugin-textdomain\' ),
\'parent_item_colon\' => __( \'Parent Books:\', \'your-plugin-textdomain\' ),
\'not_found\' => __( \'No books found.\', \'your-plugin-textdomain\' ),
\'not_found_in_trash\' => __( \'No books found in Trash.\', \'your-plugin-textdomain\' )
),
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'book\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
)
);
}