問題描述

縮圖支援正在釋出,但我有另一個稱為產品的帖子型別,它不適用於此。我正在嘗試: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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。