I added a thumbnail for next and previous post in my Wordpress theme specifically inside the single.php
file.
It works as require but it is displaying the notice:
Notice: Trying to get property of non-object in \wp-content\themes\theme\template-parts\content-footer.php on line 27
I have tried out some of the examples from similar answers in this website but they do not work for me.
I removed both $prevPost->ID
and $nextPost->ID
but it then displays the current post thumbnail instead.
The code causing the error is below: The line of code causing the notice is the 3rd and 4th lines below:
<?php
$prevPost = get_previous_post();
$nextPost = get_next_post();
$prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(50,50) );
$nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(50,50) );
?>
The thumbnails were called using the codes below:
<div class="uk-width-auto"><?php echo $prevthumbnail; ?></div>
and <div class="uk-width-auto"><?php echo $nextthumbnail; ?></div>
which both works.
The error is just a notice so it does not break the website or even appear unless wordpress debug is enabled. However, I would prefer not getting this notice so as not to cause some concern for my client.
Any idea on how to resolve this?