I’m a bit fresh to wordpress theme development (and PHP in general), and I’m curious if there is a way to query XX number of recent images, likely spanning across multiple posts. Basically I want to create a widget that shows a 3×3 set of the most recent images used in posts.
Any thoughts on how one would accomplish this?
You can use
get_posts
or create a newWP_Query
using the following args (or something similar).When looping through the images, you can use
wp_get_attachment_image
orwp_get_attachment_image_src
to grab the image HTML or image URL respectively.You’ll also want to read up the widgets API for creating widget. The codex has a basic example. There’s also quite a few tutorials out there, here’s one I wrote.