[英]create custom post type for category
How can I create a custom post type for a category like this sample.That I will input the text in the input box and fetch it as a category name. 如何为此类样本创建一个自定义帖子类型。我将在输入框中输入文本,然后将其作为类别名称获取。
public function panotour_register_post_type(){
register_post_type(self::$custom_post_type,array(
'taxonomies' => array('category'),
'name' => 'CategoryName',
'hierarchical' => true,
'query_var' => true
)
);
}
create a custom post type and add that post type to a category using taxonomies, 创建自定义帖子类型,然后使用分类法将该帖子类型添加到类别中,
function create_post_type() {
$args = array(
'label' => __( 'cpost', 'twentythirteen' ),
'description' => __( 'Custom Post Type', 'twentythirteen' ),
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'taxonomies' => array( 'category_name' ),
);
// Registering Custom Post Type
register_post_type('cpost', $args );
}
add_action( 'init', 'create_post_type', 0 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.