Last active
April 28, 2020 20:42
-
-
Save brycejacobson/bb2cb104c56593d6f1010ec5693d7ad0 to your computer and use it in GitHub Desktop.
WordPress show previous/next post navigation with thumbnail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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