Automatický náhledový obrázek

Auto Post Thumbnail…t-thumbnail/

Automatically generate the Post Thumbnail (Featured Thumbnail) from the first image in post or any custom post type only if Post Thumbnail is not set.

If the post thumbnail is already present, the plugin will do nothing. If you don't want a post thumbnail for some post with images, just add a custom field skip_post_thumb to the post and the plugin will restrain itself from generating post thumbnail. The plugin also provides a Batch Processing capability to generate post thumbnails for already published posts.

Další pluginy…tomatically/…ess-plugins/

nebo pomocí funkcí:

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);
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');


function set_first_as_featured($attachment_ID){
    $post_ID = get_post($attachment_ID)->post_parent;
        set_post_thumbnail($post_ID, $attachment_ID);
add_action('add_attachment', 'set_first_as_featured');
add_action('edit_attachment', 'set_first_as_featured');

On every upload / edit attachment, function checks if the post already has featured image. If it has not, image in question is set as featured. Every next picture will be ignored (since post already has featured image).


wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail' )[0];

Get The First Image From a Post »