WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello i wonder if anyone knows this is possible?

A post featured image click to view next post...?

For example..

<a href="next-post">
 <?php the_post_thumbnail('post-thumbnails'); ?>

I assume its something from the WordPress pagination, as when it gets to the final post/image it needs to go back to the first one.

Any idea if it can be done?

share|improve this question

Something like this should work for your single.php template:

$next_post = get_adjacent_post( false,'',false );
if( isset($next_post->ID) ):
    $next_id = $next_post->ID;
    $next_post = new WP_Query( 'posts_per_page=1&post_type=photo&order=ASC' );
    $next_id = $next_post->post->ID;
    <a href="<?php echo get_permalink( $next_id ); ?>">
        <?php echo get_the_post_thumbnail( $next_id, 'thumbnail' ); ?>
share|improve this answer
Thanks Milo, that doesn't seem to work though :( I'm using it on a single-photo.php for the custom post type photo. The usual <li><?php previous_post_link( '%link', '' . _x( '&larr;', 'Previous post link', 'twentyten' ) . ' prev' ); ?></li> <li><?php next_post_link( '%link', 'next ' . _x( '&rarr;', 'Next post link', 'twentyten' ) . '' ); ?></li> works though, fine.. – Jezthomp Sep 8 '11 at 9:18
@Jezthomp - I've modified it slightly to work with your custom post type (assuming it's called photo). I've tested here locally with a cpt to verify it's working. If you still can't get it to work, I'll have to see it in context of your theme code. – Milo Sep 9 '11 at 0:45
Brilliant that works great but is it possible just to get the link, not the image and link from the next page? Then attaching that link to the featured image on the current page, not the featured image from the next page? – Jezthomp Sep 9 '11 at 10:21
+1 for get_adjacent_post();. Hadn't heard of that function before, very useful! – aendrew Jan 16 '12 at 13:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.