問題描述
縮略圖支持正在發佈,但我有另一個稱為產品的帖子類型,它不適用於此。我正在嘗試:add_theme_support( 'post-thumbnails', array( 'post', 'product' ) );我也使用多個 post thumbnail 插件。
最佳解決方案
默認情況下,所有自定義帖子都會添加對標題和編輯器的支持,如果您想要更多的內容,如註釋,縮略圖和修訂版,則必須在支持參數中手動添加。
閲讀更多關於如何註冊您的自定義帖子類型 here,您還可以找到有關支持的部分,看看可以添加什麼。
這裏有一個例子,我們可以註冊自定義帖子的縮略圖”Books”,它支持:'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'
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);
}
add_action( 'init', 'codex_custom_init' );
次佳解決方案
對於自定義帖子,您首先必須啓用對縮略圖的支持:
add_theme_support( 'post-thumbnails' );
function theme_setup() {
register_post_type( 'yourposttype', array(
...,
'supports' => array('title', ...,'thumbnail'),
));
}
add_action( 'after_setup_theme', 'theme_setup' );
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。