Display latest 12 images from media library

Simply omit the parent value. $args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘published’, ‘numberposts’ => 12, ); Check the documentation for other arguments: Function_Reference/get_posts. Maybe you’d like to use the PHP command shuffle, like shuffle( $attachments );.

Generated media have incorrect aspect ratio

Under settings >> media, change the height attributes to 9999, and untick Crop thumbnail to exact dimensions (normally thumbnails are proportional) under the thumbnail size if it is ticked. When you are done, download and install “Force Regenerate Thumbnails”. This is actually better than “Regenerate Thumbnails” as it deletes all redundant image sizes.

How to make thumbnail image fit into a div where image dimentions are completely different?

It may be that some of your images were uploaded before you created the custom image size function. If that’s the case, a plugin like Force Regenerate Thumbnails will solve your problem. Alternatively, for more versatility you could use the images as backgrounds, like so: <div style=”background-image: url(<?php the_post_thumbnail_url(); ?>)” id=”post-thumbnail”></div> and set the background … Read more