First, I need to ask if it’s possible to create a photo gallery only with the featured images of the latest 6 posts? I assume it is possible but just want to make sure.
I don’t have much experience working directly with the wordpress gallery so could someone point me in the right direction for accomplishing this? Any plugin with similar functionally or tutorial will do.
This code gets 6 latest posts which have featured image available & show those 6 images on the page. It will skip those posts where there is no featured image set even if they are newer.
This will probably get you started. You should read the codex pages for
WP_Query
&the_post_thumbnail
As I just ran into that problem yesterday, here’s the solution: You’ll have to set
numberposts
as well asposts_per_page
to cover every edge case scenario.I also included the possibility to query for attached files as well as a check if there’re any attachments.
Note: This is just an addition to @Mridul Aggarwal answer to make it more complete. In the case this works for you, please mark his answer as solution. Thanks.