我刚创建了一个自定义分类,可以将“页面类型”添加到WordPress网站的不同页面。它们可以很好地添加到页面中,但遗憾的是我无法将这些分类法添加到CMS中的任何菜单中。每个页面都将设置为“男性”,“女性”或“信息”,因此将这些作为菜单项会很棒。我已经提供了下面的代码,任何帮助将不胜感激!谢谢!
function add_custom_taxonomies() {
// Add new "Locations" taxonomy to Posts
register_taxonomy('Page-type', 'page', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Page Types', 'taxonomy general name' ),
'singular_name' => _x( 'Page Type', 'taxonomy singular name' ),
'search_items' => __( 'Search page types' ),
'all_items' => __( 'All page types' ),
'parent_item' => __( 'Parent page type' ),
'parent_item_colon' => __( 'Parent page type:' ),
'edit_item' => __( 'Edit page type' ),
'update_item' => __( 'Update page type' ),
'add_new_item' => __( 'Add new page type' ),
'new_item_name' => __( 'New page type Name' ),
'menu_name' => __( 'Page Types' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'page-types', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/locations/"
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
),
));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
答案 0 :(得分:0)
由于数据库结构限制,分类名称应仅包含小写字母和下划线字符,且长度不得超过32个字符(Codex)。
答案 1 :(得分:0)
分类名称应该是小写,否则它不会显示在菜单中,也不会显示在show_in_nav_menus'应该是真的..