我已將代碼添加到我的function.php
文件中,以將帖子的精選圖像添加到我的管理員專欄。它適用於帖子和頁面,但對於我的兩種自定義帖子類型(汽車,輪子),它對管理佈局沒有任何作用。管理員的精選圖像專欄文章不能正常工作
有人可以幫助我嗎?我是否需要爲每個自定義添加一個過濾器?
我從這裏驗證碼:Add featured image thumbnail to WordPress admin columns
下面的代碼在我function.php
文件:
// Add the posts and pages columns filter. They can both use the same function.
add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
add_filter('manage_pages_columns', 'tcb_add_post_thumbnail_column', 5);
add_filter('manage_custom_post_columns', 'tcb_add_post_thumbnail_column', 5);
// Add the column
function tcb_add_post_thumbnail_column($cols){
$cols['tcb_post_thumb'] = __('FeaTured');
return $cols;
}
// Hook into the posts an pages column managing. Sharing function callback again.
add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
add_action('manage_custom_post_column', 'tcb_display_post_thumbnail_column', 5, 2);
// Grab featured-thumbnail size post thumbnail and display it.
function tcb_display_post_thumbnail_column($col, $id){
switch($col){
case 'tcb_post_thumb':
if(function_exists('the_post_thumbnail'))
echo the_post_thumbnail('admin-list-thumb');
else
echo 'Not supported in theme';
break;
}
}
我搜索了互聯網,但無法找到它 - 感謝這段代碼! – brendan