Get one attachment from next and previous WordPress posts
June 18, 2011 2:25 PM Subscribe
Fun WordPress question! I'm designing a template and on the image attachment page, I want to be able to display (1) the last image attached to the previous post in the category "gallery," and (2) the first image attached to the next post in the category "gallery," if there are any.
...and I am completely stumped. I'm trying to run multiple loops but nothing's doing it for me. Things I think should work fine aren't. How do I get the adjacent post and then call its first or last image? Is there any script available that does this already, or does anybody have a starting place for me?
...and I am completely stumped. I'm trying to run multiple loops but nothing's doing it for me. Things I think should work fine aren't. How do I get the adjacent post and then call its first or last image? Is there any script available that does this already, or does anybody have a starting place for me?
« Older Macbook's ability to use TV disappeared overnight!... | Boombox that plays USB sticks Newer »
This thread is closed to new comments.
$post->ID
), you're going to want to use theget_adjacent_post
function. There may be a more elegant way (or a more WordPress-ish way) but like I said, I'm not a WordPress guy. I'm not familiar with all the WordPress functions and API calls. Given WordPress' popularity, I'm very surprised that no one has chimed in here.posted by Brian Puccio at 6:30 PM on June 19, 2011