2015-10-13 57 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,所以你不必准备一个。

相关问题