为类别创建自定义帖子类型

时间:2016-06-30 06:08:19

标签: php wordpress categories

如何为此类样本创建自定义帖子类型。我将在输入框中输入文本并将其作为类别名称获取。

public function panotour_register_post_type(){
    register_post_type(self::$custom_post_type,array(
            'taxonomies' => array('category'),
            'name'         => 'CategoryName',
            'hierarchical' => true,
            'query_var' => true
        )
    );
}

1 个答案:

答案 0 :(得分:0)

创建自定义帖子类型,并使用分类法将该帖子类型添加到类别

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 );