Get thumbail of next post
-
I’m having some trouble getting reliable results from some code I wrote to get the thumbnail of the next and previous post in the single post template (single.php) to use for navigation. The posts being retrieved seem to not follow the post chronology.
I suspect the get_adjacent_post function but I can’t figure out a workaround, nor find any documentation online.
Here is the code:
<?php // Newer posts $nails_next_post = get_adjacent_post(false, '', false) ; $nails_next_post_id = $nails_next_post->ID; $nails_next_post_thumbnail = get_the_post_thumbnail($nails_next_post_id); // Get thumbnail ?> <?php if ($nails_next_post != null) : ?> <div class="post-nav-next"> <?php if ($nails_next_post_thumbnail != ''): ?> <?php echo $nails_next_post_thumbnail; ?> <?php else : ?> <img src="<?php bloginfo('template_directory'); ?>/images/default-90x90.gif" /> <?php endif; ?> <?php next_post_link('%link', 'Forward', FALSE, 3 ); ?> </div> <?php endif; ?> <?php // Older posts $nails_prev_post = get_adjacent_post(true, '', true) ; $nails_prev_post_id = $nails_prev_post->ID; $nails_prev_post_thumbnail = get_the_post_thumbnail($nails_prev_post_id); // Get thumbnail ?> <?php if ($nails_prev_post != null) : ?> <div class="post-nav-previous"> <?php if ($nails_prev_post_thumbnail != ''): ?> <?php echo $nails_prev_post_thumbnail; ?> <?php else : ?> <img src="<?php bloginfo('template_directory'); ?>/images/default-90x90.gif" /> <?php endif; ?> <?php previous_post_link('%link', 'Back', FALSE, 3 ); ?> </div> <?php endif; ?>
Anyone have any suggestions?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get thumbail of next post’ is closed to new replies.