Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
Last active April 28, 2020 20:42
Show Gist options
  • Save brycejacobson/bb2cb104c56593d6f1010ec5693d7ad0 to your computer and use it in GitHub Desktop.
Save brycejacobson/bb2cb104c56593d6f1010ec5693d7ad0 to your computer and use it in GitHub Desktop.
WordPress show previous/next post navigation with thumbnail.
<?php
// Get previous post.
$previous_post = get_previous_post( true );
if ( ! empty( $previous_post ) ) {
$prev_thumbnail = get_the_post_thumbnail( $previous_post->ID, 'thumbnail' );
} else {
$prev_thumbnail = '';
}
// Get next post.
$next_post = get_next_post( true );
if ( ! empty( $next_post ) ) {
$next_thumbnail = get_the_post_thumbnail( $next_post->ID, 'thumbnail' );
} else {
$next_thumbnail = '';
}
// Set the text for the links.
$args = array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'foundationpress' ) . '</span> <span class="screen-reader-text">' . __( 'Next post:', 'foundationpress' ) . '</span> <span class="grid-x align-middle collapse"><span class="small-9 cell"><span class="post-title">%title</span></span><span class="small-3 cell">' . $next_thumbnail . '</span></span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'foundationpress' ) . '</span> <span class="screen-reader-text">' . __( 'Previous post:', 'foundationpress' ) . '</span> <span class="grid-x align-middle collapse"><span class="small-3 cell">' . $prev_thumbnail . '</span><span class="small-9 cell"><span class="post-title">%title</span></span></span>'
);
the_post_navigation( $args );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment