I'm using the following code snippet for the next/previous navigation loop in Single.php.
<?php
$nextPost = get_next_post();
if($nextPost) {
$nextPostID = $nextPost->ID;
?>
<a class="prev-post" href="<?php echo get_permalink( $nextPostID ); ?>">
<?php echo $nextPost->post_title; ?>
</a>
<?php } else {
$first_post = get_posts( array(
'posts_per_page' => 1,
'order' => 'ASC'
) );
?>
<a class="prev-post" href="<?php echo get_permalink( $first_post[0]->ID ); ?>">
<?php echo get_the_title( $first_post[0]->ID ); ?>
</a>
<?php } ?>
<?php
$prevPost = get_previous_post();
if($prevPost) {
$prevPostID = $prevPost->ID;
?>
<a class="next-post" href="<?php echo get_permalink( $prevPostID ); ?>">
<?php echo $prevPost->post_title; ?>
</a>
<?php } else {
$latest_post = get_posts( array(
'posts_per_page' => 1,
'order' => 'DESC'
) );
?>
<a class="next-post" href="<?php echo get_permalink( $latest_post[0]->ID ); ?>">
<?php echo get_the_title( $latest_post[0]->ID ); ?>
</a>
<?php } ?>
The script is working fine but I want it to show post thumbnails with size option (small/medium/large). I tried adding <?php echo get_the_post_thumbnail( $nextPost, 'large' ); ?>
but I have to repeat it twice within the link and in each instance while it looks like it is working but the HTML produced is much like var_dump than anything:
<img width="1024" height="683" src="http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600-1024x683.jpg" class="attachment-large size-large wp-post-image" alt="" decoding="async" loading="lazy" srcset="http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600-1024x683.jpg 1024w, http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600-300x200.jpg 300w, http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600-150x100.jpg 150w, http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600-768x512.jpg 768w, http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600-1536x1024.jpg 1536w, http://localhost:8888/testsite/wp-content/uploads/2023/04/thumb-6-1600.jpg 1600w" sizes="(max-width: 1024px) 100vw, 1024px">