2015-11-14 87 views
2

我爲該帖子類型創建了自定義帖子類型和自定義分類。一切似乎都在工作......除了當我去創建一個新帖子,如果我點擊「+添加新類別」它改變了URL,但沒有任何反應。所有其他JS按鈕的工作原理,它在普通帖子上工作得很好。不知道爲什麼它這樣做。以下是我使用functions.php文件的代碼。自定義帖子類型 - 類別添加按鈕不起作用

註冊自定義文章類型

/* Custom Post Type Galleries */ 

function bhgallery_register_post_type() { 

    $singular = 'Gallery'; 
    $plural = 'Galleries'; 

    $labels = array (
     'name' => $plural, 
     'singular' => $singular, 
     'add_name' => 'Create New', 
     'add_new_item' => 'Create New ' . $singular, 
     'edit' => 'Edit', 
     'edit_item' => 'Edit ' . $singular, 
     'new_item' => 'New' . $singular, 
     'view' => 'View' . $singular, 
     'view_item' => 'View' . $singular, 
     'search_term' => 'Search ' . $plural, 
     'parent' => 'Parent ' . $singular, 
     'not_found' => 'No ' . $plural . ' Found', 
     'not_found_in_trash' => 'No ' . $plural . ' in Trash' 

    ); 

    $args = array ( 
     'labels'    => $labels, 
     'public'    => true, 
     'public_queryable'  => true, 
     'exclude_from_search' => false, 
     'show_in_nav_menus'  => true, 
     'show_in_admin_bar'  => true, 
     'menu_position'   => 10, 
     'menu_icon'    => 'dashicons-camera', 
     'can_export'   => true, 
     'delete_with_user'  => false, 
     'hierarchical'   => false, 
     'has_archive'   => true, 
     'query_var'    => true, 
     'capability_type'  => 'post', 
     'map_meta_cap'   => true, 
     // 'capabilities' => array(); 
     'rewrite'    => array(
      'slug'   => 'gallery', 
      'with_front' => true, 
      'pages'   => true, 
      'feeds'   => false, 
     ), 
     'supports'    => array(
      'title', 
      'thumbnail', 
      'editor' 
     ) 
    ); 

    register_post_type('bh_gallery', $args); 

} 

add_action ('init', 'bhgallery_register_post_type'); 

自定義分類

/** Custom Categories for Gallery **/ 

function bhgallery_register_taxonomy() { 

    $plural = 'Categories'; 
    $singular = 'Category'; 

    $labels = array (
      'name'      => $plural, 
      'singular_name'    => $singular, 
      'search_items'    => 'Search ' . $plural, 
      'popular_items'    => 'Popular ' . $plural, 
      'all_items'     => 'All ' . $plural, 
      'parent_item'    => null, 
      'parent_item_colon'   => null, 
      'edit_item'     => 'Edit ' . $singular, 
      'update_item'    => 'Update ' . $singular, 
      'add_new_item'    => 'Add New ' . $singular, 
      'new_item_name'    => 'New ' . $singular . ' Name', 
      'separate_items_with_comas' => 'Seperate ' . $singular . ' with commas', 
      'add_or_remove_items'  => 'Add or remove ' . $plural, 
      'choose_from_most_used'  => 'Choose from the most used ' . $plural, 
      'not_found'     => 'No ' . $plural . 'fount', 
      'menu_name'     => $plural, 
     ); 

    $args = array (
     'hierarchical'   => true, 
     'labels'    => $labels, 
     'show_ui'    => true, 
     'show_admin_column'  => true, 
     'update_count_callback' => '_update_post_term_count', 
     'query_var'    => true, 
     'rewrite'    => array('slug' => 'categories'), 
     ); 

    register_taxonomy('gallery category', 'bh_gallery', $args); 
} 

add_action ('init', 'bhgallery_register_taxonomy'); 

如果有其他任何你需要知道的,讓我知道。上述

+0

我也經歷了http://codex.wordpress.org/Using_Your_Browser_to_Diagnose_JavaScript_Errors上的步驟,並沒有發現任何錯誤 –

回答

2

你的第二個代碼最後一行有

register_taxonomy('gallery category', 'bh_gallery', $args);

從抄本,register taxonomy,第一個參數不應該有任何的空間。實際上,空間是非常少的地方,而且它們主要限於用於顯示的字符串。

$ taxonomy(string)(required)分類的名稱。名稱應該是 只包含小寫字母和下劃線字符,而不是 長度超過32個字符(數據庫結構限制)。

+0

BLAST !!!只是它總是愚蠢的我做到了! :) 謝謝! –

相關問題