I have a wordpress theme i’m customising. The theme has a masonry script which puts all the posts into an order and uses the featured image as the thumbnail. once you click a thumbnail it takes you to the single post page where the featured image is big.
I’m stuck trying to change the url of the image in that page to go to the next post, every time I try it relinks to itself. Heres the current section from the single.php that I need help changing. Would anyone know how to change it correctly to do this?
you can use the get_next_post() function to return the post object of the next post.
<?php $next_post = get_next_post();
// Check to make sure a next post exists to prevent getting an PHP property of non object warning
$url = is_object( $next_post ) ? get_permalink( $next_post->ID ) : '';
// Get the title of the next post to use in the link title attribute
$title = is_object( $next_post ) ? get_the_title( $next_post->ID ) : ''; ?>
<a href="<?php echo esc_url( $url ) ?>" title="<?php echo esc_attr( $title ); ?>" class="prettyphoto-link"><?php the_post_thumbnail('post-full'); ?></a>