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?

1 Answer 1


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' ); ?>
  • 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, 2011 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, 2011 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, 2011 at 10:21
  • +1 for get_adjacent_post();. Hadn't heard of that function before, very useful!
    – aendra
    Jan 16, 2012 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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