Show Previous & Next Post In Single Post

Share Now

PREVIOUS POST

<?php esc_html_e( 'Previous post', $domain = 'awa47-nmh47' ); ?>
<?php
   $prevPost = get_previous_post();
   ?>
<?php if (empty( $prevPost )): ?>
<p>No Previous Post</p>
<?php endif; ?>
<?php if (!empty( $prevPost )): ?>
<?php $p_t_image = wp_get_attachment_image_src( get_post_thumbnail_id( $prevPost->ID ), 'single-post-thumbnail' );
   ?>
<img class="post-nav-img" src="<?php echo $p_t_image[0]; ?>" alt="">
<a href="<?php echo get_permalink( $prevPost->ID ); ?>" class="content"><?php echo get_the_title($prevPost) ?></a>
<?php endif; ?>

NEXT POST


<?php esc_html_e( 'Next post', $domain = 'awa47-nmh47' ); ?> 
<?php
   $nextPost = get_next_post();
   ?>
<?php if (empty( $nextPost )): ?>
<p>No Next Post</p>
<?php endif; ?>
<?php if (!empty( $nextPost )): ?>
<?php $n_t_image = wp_get_attachment_image_src( get_post_thumbnail_id( $nextPost->ID ), 'single-post-thumbnail' );
?>
<img class="post-nav-img" src="<?php echo $n_t_image[0]; ?>" alt="">
<a href="<?php echo get_permalink( $nextPost->ID ); ?>" class="content"><?php echo get_the_title($nextPost) ?></a>
<?php endif; ?>

Picture of Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert