Fimg02
文章控制台裡面的欄位很少,除了『作者、分類、標籤、迴響、日期』這些欄位之外,想要增加『特色圖片』的欄位怎麼做?

首先要使用這個功能,也要先讓佈景支援特色圖片,在 functions.php 寫下這一列:

add_theme_support('post-thumbnails');

再把以下兩個函數貼上去

function ST4_columns_head($defaults) {
    $defaults['featured_image'] = '特色圖片';
    return $defaults;
}
function ST4_columns_content($column_name, $post_ID) {
    if ($column_name == 'featured_image') {
        $post_thumbnail_id = get_post_thumbnail_id($post_ID);
        if ($post_thumbnail_id) {
          $post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id);
          if ( $post_thumbnail_img[0] ){
              echo '<img src="' . $post_thumbnail_img[0] . '" />';
          }
        }
    }
}

 

若想要在文章(Posts)和自定頁面(Custom Post Types)顯示:

add_filter('manage_posts_columns', 'ST4_columns_head');
add_action('manage_posts_custom_column', 'ST4_columns_content', 10, 2);

 

若只想要在文章(Posts)畫面中顯示:

add_filter('manage_post_posts_columns', 'ST4_columns_head', 10);
add_action('manage_post_posts_custom_column', 'ST4_columns_content', 10, 2);

 

若只想要在頁面(Page)畫面中顯示:

add_filter('manage_page_posts_columns', 'ST4_columns_head', 10);
add_action('manage_page_posts_custom_column', 'ST4_columns_content', 10, 2);

 

若只想要在某一個自定頁面(Custom Post Types)顯示,底下是命名在’book’:

add_filter('manage_book_posts_columns', 'ST4_columns_book_head');
add_action('manage_book_posts_custom_column', 'ST4_columns_book_content', 10, 2);

Fimg01
最後記得要打開『顯示選項』,去勾選『特色圖片』才完成。