發現一個小hack,很方便使用,將下方代碼新增到Theme Functions (functions.php)最下方的
?>
之前即可。 ?
/* 設定所有文章第一個為特色圖片開始(由AREFLY.COM製作) */
function autoset_featured_image(){
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb){
$attached_image = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" ? ;
if ($attached_image){
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
}
add_action('the_post', 'autoset_featured_image');
add_action('save_post', 'autoset_featured_image');
add_action('draft_to_publish', 'autoset_featured_image');
add_action('new_to_publish', 'autoset_featured_image');
add_action('pending_to_publish', 'autoset_featured_image');
add_action('future_to_publish', 'autoset_featured_image');
/* 設定所有文章第一個為特色圖片開始(由AREFLY.COM製作) */
資訊出處:WordPress自動設定新文章第一張映像為特色映像 | 暢想資源 [1]
