我尝试使用WordPress中的分类法为我的主题创建自定义帖子,我的自定义帖子工作正常,但我的分类法没有显示在admin 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);
答案 0 :(得分:0)
使用以下代码注册自定义分类,它肯定会起作用。 :)
//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' ),
));
}
答案 1 :(得分:0)
这是答案 我花了将近6个小时来找到问题,但没有结果,所以我用准确的名称重写了分类法部分..... 问题解决了。 我不确切知道WordPress有什么问题。真的6个小时什么都没有?