WordPress 3.2中的自定义发布类型中缺少特色图像面板

时间:2011-10-13 作者:Devise

从3.1升级到3.2,并在admin中丢失了在自定义帖子类型中运行的特色图像面板。

add_action( \'init\', \'create_my_post_types\' );

function create_my_post_types() {
    register_post_type( \'header_image_gallery\',
        array(
            \'labels\' => array(
            \'name\' => __( \'Header Images\' ),
            \'singular_name\' => __( \'Header Image\' ),
            \'add_new\' => __( \'Add New\' ),
            \'add_new_item\' => __( \'Add New Header Image\' ),
            \'edit\' => __( \'Edit\' ),
            \'edit_item\' => __( \'Edit Header Image\' ),
            \'new_item\' => __( \'New Header Image\' ),
            \'view\' => __( \'View Header Images\' ),
            \'view_item\' => __( \'View Header Images\' ),
            \'search_items\' => __( \'Search Header Images\' ),
            \'not_found\' => __( \'No Header Images found\' ),
            \'not_found_in_trash\' => __( \'No Header Images found in Trash\' ),
            \'parent\' => __( \'Parent Header Images\' ),
            ),
            \'public\' => true,
            \'supports\' => array(\'title\',\'thumbnail\',\'revisions\')
        )
    );
}
Post缩略图的注册方式如下:

// This theme uses post thumbnails
    add_theme_support( \'post-thumbnails\', array(\'post\', \'page\') );
注意:升级之前创建的自定义帖子在前端正常工作,显示其帖子缩略图(只缺少特色图片管理面板)。

另外:我已经去了抄本,拉了一个自定义帖子类型的例子,你会注意到它应该显示一个特色图片>,但也没有。

add_action(\'init\', \'codex_custom_init\');
function codex_custom_init() 
{
  $labels = array(
    \'name\' => _x(\'Books\', \'post type general name\'),
    \'singular_name\' => _x(\'Book\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'book\'),
    \'add_new_item\' => __(\'Add New Book\'),
    \'edit_item\' => __(\'Edit Book\'),
    \'new_item\' => __(\'New Book\'),
    \'all_items\' => __(\'All Books\'),
    \'view_item\' => __(\'View Book\'),
    \'search_items\' => __(\'Search Books\'),
    \'not_found\' =>  __(\'No books found\'),
    \'not_found_in_trash\' => __(\'No books found in Trash\'), 
    \'parent_item_colon\' => \'\',
    \'menu_name\' => \'Books\'

  );
  $args = array(
    \'labels\' => $labels,
    \'public\' => true,
    \'publicly_queryable\' => true,
    \'show_ui\' => true, 
    \'show_in_menu\' => true, 
    \'query_var\' => true,
    \'rewrite\' => true,
    \'capability_type\' => \'post\',
    \'has_archive\' => true, 
    \'hierarchical\' => false,
    \'menu_position\' => null,
    \'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\',\'comments\')
  ); 
  register_post_type(\'book\',$args);
}
如果我检查屏幕选项,则在两个示例中都看不到特征图像选项。

*回答了我自己的问题

也许在WP 3.1中,您在添加主题支持时不必声明自定义帖子类型,但在WP 3.2中,您可以这样做!

// This theme uses post thumbnails
    add_theme_support( \'post-thumbnails\', array(\'post\', \'page\',\'header_image_gallery\') );

3 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

更改此项:

// This theme uses post thumbnails
add_theme_support( \'post-thumbnails\', array(\'post\', \'page\') );
对此:

// This theme uses post thumbnails
add_theme_support( \'post-thumbnails\' );
问题是数组在使用时是显式的。因此,只有将帖子缩略图支持添加到数组中包含的帖子类型中。

省略该数组,以便为帖子缩略图添加主题支持。

SO网友:Muhammad Sadiq

试试这个,对我有用。

add_theme_support(\'post-thumbnails\');
add_post_type_support( \'my_product\', \'thumbnail\' );

function create_post_type() {
    register_post_type( \'my_product\',
        array(
            \'labels\' => array(
                \'name\' => __( \'Products\' ),
                \'singular_name\' => __( \'Product\' )
            ),
            \'public\' => true,
            \'has_archive\' => true
        )
    );
}
add_action( \'init\', \'create_post_type\' );

SO网友:Shakeer

在函数中查找此代码。php

    \'supports\'              => array( ),
将代码更改为

    \'supports\'              => array( \'thumbnail\', ),
如果在函数中创建了自定义帖子类型,则可以实现此解决方案。php

结束

相关推荐