在Wordpress上创建Custum Texonomy和Post Type

时间:2015-09-18 10:56:30

标签: php wordpress

我正在尝试在wordpress上创建custum Texonomy。如何创建它?

这是我的代码:

add_action( 'init', 'create_post' );
    function create_post() {

        $labels = array(
            'name' => _x('Post', 'Post General Name', 'gdl_back_office'),
            'singular_name' => _x('Speakpool Item', 'Post Singular Name', 'gdl_back_office'),
            'add_new' => _x('Add New', 'Add New Post Name', 'gdl_back_office'),
            'add_new_item' => __('Author Name', 'gdl_back_office'),
            'edit_item' => __('Author Name', 'gdl_back_office'),
            'new_item' => __('New Post', 'gdl_back_office'),
            'view_item' => '',
            'search_items' => __('Search Post', 'gdl_back_office'),
            'not_found' =>  __('Nothing found', 'gdl_back_office'),
            'not_found_in_trash' => __('Nothing found in Trash', 'gdl_back_office'),
            'parent_item_colon' => ''
        );

        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            //'menu_icon' => GOODLAYERS_PATH . '/include/images/portfolio-icon.png',
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'menu_position' => 5,
            "show_in_nav_menus" => false,
            'exclude_from_search' => true,
            'supports' => array('title','editor','author','thumbnail','excerpt','comments')
        ); 

        register_post_type( 'Post' , $args);

        register_taxonomy( 'Post_category', 'Post', array( 
            'hierarchical' => true, 'label' => 'Post Category', 'query_var' => true, "show_in_nav_menus" => true, 'rewrite' => true ) );

    }

它创建Custum Post类型但不是Texonomy不起作用。帮助我。

1 个答案:

答案 0 :(得分:3)

删除register_taxonomy()并尝试使用此代码更改名称:

function create_video_blog_taxonomies() {
    $labels = array(
        'name'              => _x( 'Video Categories', 'taxonomy general name' ),
        'singular_name'     => _x( 'Category', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Categories' ),
        'all_items'         => __( 'All Categories' ),
        'parent_item'       => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item'         => __( 'Edit Category' ),
        'update_item'       => __( 'Update Category' ),
        'add_new_item'      => __( 'Add New Category' ),
        'new_item_name'     => __( 'New Category Name' ),
        'menu_name'         => __( 'Video Categories' ),
    );

    $args = array(
        'hierarchical'      => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'categories' ),
    );

    register_taxonomy( 'video_blog_categories', array( 'video_blog' ), $args );
}
add_action( 'init', 'create_video_blog_taxonomies', 0 );

单独的Custum帖子类型功能和Texomony功能