我已经成功创建了一个自定义帖子类型(又名“指令”)和两个不同的类别(又名“程序”和“练习”)。“指令”需要在“练习”下归档,练习需要将“程序”作为父类别。
以下是我注册分类法的方式:
function create_taxonomy() {
$programLabels = array(
\'name\' => _x( \'Programs\', \'taxonomy general name\' ),
\'singular_name\' =>_x( \'Program\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Programs\' ),
\'popular_items\' => __( \'Popular Programs\' ),
\'all_items\' => __( \'All Programs\' ),
\'edit_item\' => __( \'Edit Program\' ),
\'update_item\' => __( \'Update Program\' ),
\'add_new_item\' => __( \'Add New Program\' ),
\'new_item_name\' => __( \'New Program\' ),
\'separate_items_with_commas\' => __( \'Separate programs with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove programs\' ),
\'choose_from_most_used\' => __( \'Choose from the most used programs\' )
);
register_taxonomy(
\'category_program\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'cus_instruction\', // post type name
array(
\'hierarchical\' => false,
\'label\' => __(\'Program\'),
\'labels\' => $programLabels,
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'program\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
$exerciseLabels = array(
\'name\' => _x( \'Exercises\', \'taxonomy general name\' ),
\'singular_name\' =>_x( \'Exercise\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Exercises\' ),
\'popular_items\' => __( \'Popular Exercises\' ),
\'all_items\' => __( \'All Exercises\' ),
\'parent_item\' => __( \'Program\' ),
\'parent_item_colon\' => ( \'Program:\' ),
\'edit_item\' => __( \'Edit Exercise\' ),
\'update_item\' => __( \'Update Exercise\' ),
\'add_new_item\' => __( \'Add New Exercise\' ),
\'new_item_name\' => __( \'New Exercise\' ),
\'separate_items_with_commas\' => __( \'Separate exercises with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove exercise\' ),
\'choose_from_most_used\' => __( \'Choose from the most used exercises\' ),
\'menu_name\' => __( \'Exercises\' )
);
register_taxonomy(
\'category_exercise\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'cus_instruction\', // post type name
array(
\'hierarchical\' => true,
\'label\' => __(\'Exercise\'),
\'labels\' => $exerciseLabels,
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'exercise\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
}
add_action( \'init\', \'create_taxonomy\', 0);
从概念上讲,将“cus\\u指令”设置为类别“Program”的post类型是不正确的,但这是我可以让Wordpress在管理侧栏中显示它的唯一方法。在“Exercise”类别中设置“parent\\u item”不会将类别“Program”绑定为父类别,但只会更改父类别的标签。
我的要求在Wordpress中是否可行?如果是,我如何设置类别结构?