簡體   English   中英

創建類別的自定義帖子類型

[英]create custom post type for category

如何為此類樣本創建一個自定義帖子類型。我將在輸入框中輸入文本,然后將其作為類別名稱獲取。

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

創建自定義帖子類型,然后使用分類法將該帖子類型添加到類別中,

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM