添加到菜单时自定义分类无效



我刚刚创建了一个自定义分类法,将"页面类型"添加到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 );

由于数据库结构限制,分类名称应仅包含小写字母和下划线字符,并且长度不应超过 32 个字符 (Codex(。

分类

名称应为小写,否则它不会显示在菜单中,并且"show_in_nav_menus"也应为真。

最新更新