WordPress.org

Ready to get started?Download WordPress

Ideas

If no post_thumbnail() defined, use first uploaded image

  1. Mehmet
    Member

    12345

    Some blogs have tens, some hundreds while some have thousands posts published. Going back to edit each post to define a post thumbnail is highly time consuming.

    Would be a neat feature if WordPress itself would define very first uploaded photo as post_thumbnail if there is not any defined by user yet.

    Posted: 4 years ago #
  2. khena25
    Member

    12345

    I would like something like this too.

    Posted: 4 years ago #
  3. Jen Mylo
    Key Master

    12345

    You say "going back," implying that the problem is not with new posts, but with old posts. Since this would be a one-time retroactive function, I think this would be better handled by a plugin.

    Posted: 4 years ago #
  4. kwatog
    Member

    this can be handled by the template... here's the function that I created.

    function get_attachment_image($postid=0, $size='thumbnail') {
            $image_path = get_post_meta($postid, 'Thumbnail', true);
    	if (!empty($image_path)){
    	   return $image_path;
    	}
    	else {
                if ($postid<1) {
                  $postid = get_the_ID();
                }
                $images = get_children(array(
                        'post_parent' => $postid,
                        'post_type' => 'attachment',
                        'numberposts' => 1,
                        'post_mime_type' => 'image',));
    
                if (isset($image)){
                    foreach($images as $image) {
                             $image_array = image_downsize( $image->ID, $size);
                             $image_path  = $image_array[0];
                             return $image_path;
                    }
                }
    	}
    	if ($image_path == ""){
    	  $image_path = get_post_meta($post->ID, 'post-image', true);
    	}
    	else {
    	   return $image_path;
    	}
    
    	if ($image_path != ""){
    	  return $image_path;
        } else {
    	   $image_path = get_bloginfo('template_directory')."/images/no-pic.png";
    	   return $image_path;
    	}
    	//if it comes here, no image found.
    }

    and this is called by

    if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
      echo get_the_post_thumbnail($post->ID,array(150,150));
    } else {
       $postimage = get_attachment_image($post->ID);
       if ($postimage) {
       echo '<img src="'.$postimage.'" alt="" class="wp-post-image"/>';
    }
    }

    hope this helps.

    Posted: 4 years ago #
  5. thanks man!

    Posted: 3 years ago #
  6. arunramanunnni
    Member

    12345

    If no post_thumbnail() defined, use first uploaded image
    yes this comment is correct

    Posted: 3 years ago #
  7. I must say that there is nothing more irritating than editing all the posts one by one, when it comes to blogs. It is simply annoying. The main reason is that we just cannot determine how many posts are there in a blog and that alone can be very exasperating. Then to go and edit each one of them is simply out of the question. I guess it is hard time that the health of these blogs be renewed with a suitable plug-in!

    Posted: 3 years ago #
  8. IP PBX
    Member

    I must say that there is nothing more irritating than editing all the posts one by one, when it comes to blogs. It is simply annoying. The main reason is that we just cannot determine how many posts are there in a blog and that alone can be very exasperating. Then to go and edit each one of them is simply out of the question. I guess it is hard time that the health of these blogs be renewed with a suitable plug-in!

    Posted: 3 years ago #
  9. jrothe
    Member

    Or even just having the option to set a default image, that somehow could be retroactive. But for large content networks, that might be problematic, but even a simple button press, or set of checkboxes in the full post view to apply the default would be nice.

    Posted: 3 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    6 Votes
  • Status

    This is plugin territory