2015-10-13 56 views
2

在wp-admin中,我創建了一個新的管理菜單頁面。Wordpress設置自定義文章類型的特色圖像

add_menu_page('My custom post page type title', 'My custom post type menu', '', 'my-custom-slug', '', '', 99); 
add_submenu_page('my-custom-slug', 'Add new', 'Add new', 'manage_options', 'post-new.php?post_type=my-custom-post-type', ''); 

我想使用像post-new.php和edit.php這樣的面板,所以我註冊了一個自定義的帖子類型。

register_post_type('my-custom-post-type', 
        array('labels'=>array('name'=>__('Products','text-domain'), 
             'singular_name'=>__('Product','text-domain'), 
             'menu_name'=>_x('Products','Admin menu name','text-domain'), 
             'add_new'=>__('Add Product','text-domain'), 
             'add_new_item'=>__('Add New Product','text-domain'), 
             'edit_item'=>__('Edit Product','text-domain'), 
             'new_item'=>__('New Product','text-domain'), 
             'view_item'=>__('View Product','text-domain'), 
             'not_found'=>__('No Products found','text-domain'), 
             'not_found_in_trash'=>__('No Products found in trash','text-domain')), 
         'supports'=>array('title','editor','thumbnail','comments') 
         'rewrite'=>array('slug'=>'mscases'), 
         'public'=>true, 
         'capability_type'=>'post')); 

自定義菜單頁能正常工作,而元框Featured Image也工作得很好,我可以選擇圖像中的媒體庫。

當我選擇圖片後,它不會出現在精選圖片元框中,並且admin-ajax.php響應是-1(我檢查帖子頁面,如果成功,則爲零)。

但是,如果我將參數my-custom-post-type更改爲product(如woocommerce),則會顯示我選取的精選圖像。

有沒有什麼我想念編碼?

回答

0

更換,並嘗試

register_post_type('my-custom-post-type', 
    array('labels' => array('name' => __('Products', 'text-domain'), 
      'singular_name' => __('Product', 'text-domain'), 
      'menu_name' => _x('Products', 'Admin menu name', 'text-domain'), 
      'add_new' => __('Add Product', 'text-domain'), 
      'add_new_item' => __('Add New Product', 'text-domain'), 
      'edit_item' => __('Edit Product', 'text-domain'), 
      'new_item' => __('New Product', 'text-domain'), 
      'view_item' => __('View Product', 'text-domain'), 
      'not_found' => __('No Products found', 'text-domain'), 
      'not_found_in_trash' => __('No Products found in trash', 'text-domain')), 
     'supports' => array('title', 'editor', 'thumbnail', 'comments'), 
     'rewrite' => array('slug' => 'mscases'), 
     'public' => true, 
     'capability_type' => 'post')); 
0

當您創建自定義類型後從來不使用「 - 」符號,請使用「_」,而不是「 - 」。

我在過去有同樣的問題,我已經改變,它爲我工作。

0

谷歌搜索這個問題,最後我發現問題是。

您必須使用add_action並將鉤子設置爲init

add_action('init', array('MyClass', 'RegisterPostType'));

而且功能的圖像效果還算不錯。

0

你必須通過的functions.php將這個先告訴WordPress的,你的主題支持功能的圖像:

add_action('after_setup_theme', 'umbrella_theme_setup'); 
function umbrella_theme_setup(){ 
    add_theme_support('post-thumbnails'); 
} 

而不是你需要啓用自定義信息功能的圖像:

register_post_type('my-custom-post-type', 
        array('labels'=>array('name'=>__('Products','text-domain'), 
             'singular_name'=>__('Product','text-domain'), 
             'menu_name'=>_x('Products','Admin menu name','text-domain'), 
             'add_new'=>__('Add Product','text-domain'), 
             'add_new_item'=>__('Add New Product','text-domain'), 
             'edit_item'=>__('Edit Product','text-domain'), 
             'new_item'=>__('New Product','text-domain'), 
             'view_item'=>__('View Product','text-domain'), 
             'not_found'=>__('No Products found','text-domain'), 
             'not_found_in_trash'=>__('No Products found in trash','text-domain')), 
         'supports'=>array('title','editor','thumbnail','comments') 
         'rewrite'=>array('slug'=>'mscases'), 
         'public'=>true, 
         'capability_type'=>'post')); 

精選圖片元應該現在出現在您的自定義帖子中,並且the_post_thumnail();函數應該可以工作。 你必須刪除sub_menu_page和menu_page,因爲WordPress爲他們顯示了一個UI,所以你不必準備一個。

相關問題