Chaotic lines | 第一张图自动生成featured image
This site is a portfolio of Ray . Hope you enjoy it!
故事板,分镜头,storyboard,电影分镜,分镜师,storyboard artist
3765
post-template-default,single,single-post,postid-3765,single-format-standard,ajax_updown_fade,page_not_loaded,,qode-child-theme-ver-1.0.0,qode-theme-ver-3.6,wpb-js-composer js-comp-ver-5.4.5,vc_responsive
 

Blog

第一张图自动生成featured image

  |   Geek   |   No comment

wordpress第一张图自动生成featured image

同样是functions.php文件添加函数:

function autoset_featured() {
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);
}
}
}
} //end function
add_action(‘the_post’, ‘autoset_featured’);
add_action(‘save_post’, ‘autoset_featured’);
add_action(‘draft_to_publish’, ‘autoset_featured’);
add_action(‘new_to_publish’, ‘autoset_featured’);
add_action(‘pending_to_publish’, ‘autoset_featured’);
add_action(‘future_to_publish’, ‘autoset_featured’);

20130418-070139.jpg

No Comments

Post A Comment