0

I am using a fork from underscores.io, and there is this code:

next_post_link(     '<div class="nav-next">%link</div>',     _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link',     'nicosite' ) );

Wich prints the next post link,

How Can I use it (or alternatives) to include the post's thumbnail?

-edit-

Right now, I have

 next_post_link(     '<div class="nav-next">%link</div>',     _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link',     'nicosite' ) );
 $nextPost = get_next_post(true); $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(300,150) ); 
 echo $nextthumbnail;

That it prints out the image, but this way I get outside the a...

1

If you have a look at what next_post_link you'll see that it takes a parameter $link as the second argument:

next_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' );

Your parameter for this currently doesn't include the post thumbnail:

_x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'nicosite' )

So we need to add it like this:

$nextPost = get_next_post(true); // You are aware that this only checks for next posts in the same term, right? 
if(!empty($nextPost) ){ //This is to check if there is a next post
    $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(300,150) );
}else{
    $nextthumbnail ='';
}
next_post_link( '<div class="nav-next">%link</div>', $nextthumbnail . _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', nicosite' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.