Get all images from posts with maximum number and without featured image

Try this: $image_count = 0; $max_images = 10; //set this to the max number of images you want. $ids = get_posts( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 ,’fields’ =>’ids’) ); if (count($ids) > 0){ foreach ($ids as $id){ while ($image_count < $max_images){ $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, … Read more

Featured Image Thumbnail Sizing

I’ve approached this problem in a few different ways, here’s some ideas: Just grad the medium sized thumbnail with the_post_thumbnail(‘medium’); (or any defined size that is bigger than what you want displayed), and apply a .inner .thumb img {width: 153px; height: auto;} css rule. If it’s too tall it will get cropped from your overflow:hidden; … Read more

Automatic adding thumbnail to post

This should work: $wp_upload_dir = wp_upload_dir(); $fileurl = “http://damianc.pl/th.jpg”; $filename = $upload_dir[‘path’] . DIRECTORY_SEPARATOR . basename( $fileurl ); if ( file_put_contents( $filename, file_get_contents( $fileurl ) ) ) { require_once(ABSPATH . ‘wp-admin/includes/image.php’); $wp_filetype = wp_check_filetype(basename($filename), null); $attachment = array( ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ); $attach_id = … Read more

Thumbnail images

Inside your post loop you can do; if ( has_post_thumbnail()) { echo get_the_post_thumbnail($post->ID, ‘thumbnail’); } This first checks for the existence of a featured image and if so it will display one at your default ‘thumbnail’ size as set in your settings/media options. This would also work within your loop; if ( has_post_thumbnail()) { the_post_thumbnail(‘thumbnail’); … Read more

trouble with the_post_thumbnail

In your work.php code sample you are calling get_post_meta( $post->ID, ‘the_post_thumbnail’, true) This has nothing to do with WordPress post thumbnails and is looking for a custom field with the post meta key ‘the_post_thumbnail’ For more info see: get_post_thumbnail_id wp_get_attatchment_image_src Post Thumbnails To get the src url of the featured image attached to the post … Read more

Wrap Featured Image in a Link

Unless there’s some part of your problem I don’t grasp, what’s wrong with a simple mash-up of the two given snippets? <?php global $post; $urlbox = get_url_desc_box(); $post_thumb = get_the_post_thumbnail( $post->ID, ‘screenshot’ ); if( !empty( $urlbox[0] ) && !empty( $post_thumb ) ) { echo sprintf( ‘<a target=”_blank” href=”https://wordpress.stackexchange.com/questions/66759/%1$s”>%2$s</a>’, $urlbox[0], $post_thumb ); } ?> Edited: get_the_post_thumbnail … Read more

Missing thumbnails

Seems to me you use a WordPress theme which uses some kind of php library to resize images. You should really use WordPress default add_image_size() and wp_get_attachment_image but if you were the one who created the theme you would already know that. There are 3 things you can do: find a new theme that is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)