WordPress分类不适用于我的自定义帖子类型
问题描述:
我尝试使用WordPress主题中的分类标准创建自定义帖子,但我的自定义帖子正常,但我的分类标准未显示在管理wordpress面板中。WordPress分类不适用于我的自定义帖子类型
我写这部分代码在其他页面命名library.inc.php
,我包括在function.php
我找不到地方到底是什么问题?
这里是我的代码
function p2p2_register_book(){
$labels = array(
'name' => _x('کتابخانه', 'books'),
'singular_name' => _x('کتاب', 'book'),
'add_new' => _x('افزودن کتاب', ''),
'add_new_item' => __('افزودن کتاب جدید'),
'edit_item' => __('ویرایش کتاب'),
'new_item' => __('کتاب جدید'),
'all_items' => __('همه کتاب ها'),
'view_item' => 'View Book',
'search_items' => __('جست و جو کتاب'),
'not_found' => _('کتاب یافت نشد'),
'not_found_in_trash' => __('کتاب در زباله دان یافت نشد'),
'parent_item_colon' => '',
'menu_name' => 'کتابخانه'
);
$args=array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'menu_position' => 2,
'rewrite' => array('slug' => 'book'),
'capability_type' => 'page',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'thumbnail', 'comments' ,'custom-fields'),
// 'taxonomies' => array('Books_category','post_tag'),
);
register_post_type('Book',$args);
}
add_action('init', 'p2p2_register_book');
,这里是分类部分
function wp_library_post_taxonomy() {
register_taxonomy(
'Books_category', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'Book', //post type name
array(
'hierarchical' => true,
'label' => 'دسته بندی کتاب', //Display name
'query_var' => true,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'Books-category', // This controls the base slug that will display before each term
'with_front' => true // Don't display the category base before
)
)
);
}
add_action('init', 'wp_library_post_taxonomy');
include_once('mixitup-plug.php');
add_theme_support('post_thumbnails');
add_image_size('Books_small_image',150,200,true);
答
使用下面的代码来注册自定义分类,将definetly工作。 :)
//hook into the init action and call create_book_taxonomies when it fires
add_action('init', 'wp_library_post_taxonomy', 0);
//create a custom taxonomy name it topics for your posts
function wp_library_post_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x('Taxonomy Names', 'taxonomy general name'),
'singular_name' => _x('Taxonomy Name', 'taxonomy singular name'),
'search_items' => __('Search Taxonomy Names'),
'all_items' => __('All Taxonomy Names'),
'parent_item' => __('Parent Taxonomy Names'),
'parent_item_colon' => __('Parent Taxonomy Name:'),
'edit_item' => __('Edit Taxonomy Name'),
'update_item' => __('Update Taxonomy Name'),
'add_new_item' => __('Add New Taxonomy Name'),
'new_item_name' => __('New Granite Taxonomy Name'),
'menu_name' => __('Taxonomy Name'),
);
// Now register the taxonomy
register_taxonomy('Taxonomy Name',array('custom_post_type name'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'Taxonomy Name'),
));
}
答
这里就是答案 我花6附近小时,我重写与确切名称的分类部分,..... 问题解决了,找到问题,但没有结果。 我不知道WordPress究竟发生了什么问题。真的6个小时没有?