Вы хотите определить свою таксономию и пользовательский тип записи в файле functions.php, используя функции register_taxonomy()
и register_post_type()
.
Вот пример того, как это может выглядеть:
/****************************************
* Add custom taxonomy for Toys *
****************************************/
add_action('init', 'toys_categories_register');
function toys_categories_register() {
$labels = array(
'name' => 'Toys Categories',
'singular_name' => 'Toys Category',
'search_items' => 'Search Toys Categories',
'popular_items' => 'Popular Toys Categories',
'all_items' => 'All Toys Categories',
'parent_item' => 'Parent Toy Category',
'edit_item' => 'Edit Toy Category',
'update_item' => 'Update Toy Category',
'add_new_item' => 'Add New Toy Category',
'new_item_name' => 'New Toy Category',
'separate_items_with_commas' => 'Separate toys categories with commas',
'add_or_remove_items' => 'Add or remove toys categories',
'choose_from_most_used' => 'Choose from most used toys categories'
);
$args = array(
'label' => 'Toys Categories',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'toys', 'with_front' => true, 'hierarchical' => true ),
'query_var' => true
);
register_taxonomy( 'toys_categories', 'toys', $args );
}
/*****************************************
* Add custom post type for Toys *
*****************************************/
add_action('init', 'toys_register');
function toys_register() {
$labels = array(
'name' => 'Toys',
'singular_name' => 'Toy',
'add_new' => 'Add New',
'add_new_item' => 'Add New Toy',
'edit_item' => 'Edit Toy',
'new_item' => 'New Toy',
'view_item' => 'View Toy',
'search_items' => 'Search Toys',
'not_found' => 'Nothing found',
'not_found_in_trash' => 'Nothing found in Trash',
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'toys', 'with_front' => true ),
'capability_type' => 'post',
'menu_position' => 6,
'supports' => array('title', 'excerpt', 'editor','thumbnail') //here you can specify what type of inputs will be accessible in the admin area
);
register_post_type( 'toys' , $args );
}
Затем вам нужно зайти в админ-панель администратора, и вы должны увидеть игрушки прямо под сообщением. Создайте категории, которые вам нужны, в разделе «Категории игрушек».