Užitečné pluginy, návody a šablony pro WordPress CMS

Automatický náhledový obrázek

Auto Post Thumbnail
http://wordpress.org/…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
http://beginnersbook.com/…tomatically/
http://wpfreesetup.com/…ess-plugins/

nebo pomocí funkcí:

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

alternativně

function set_first_as_featured($attachment_ID){
    $post_ID = get_post($attachment_ID)->post_parent;
    if(!has_post_thumbnail($post_ID)){
        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).

případně

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

Get The First Image From a Post »

OVX.cz 2003 | Přihlásit se
Bez cookies už dnes těžko provozovat plnohodnotný web. Setrváním zde tudíž vyjadřujete souhlas s jejich používáním. Více informací. | Zavřít.