调整NEXT_POST_LINK以包括缩略图

时间:2015-08-22 作者:Toni Michel Caubet

我使用下划线中的叉。io,有以下代码:

next_post_link(     \'<div class="nav-next">%link</div>\',     _x( \'%title <span class="meta-nav">&rarr;</span>\', \'Next post link\',     \'nicosite\' ) );
Wich打印下一个帖子链接,

我如何使用它(或其他选项)来包含帖子的缩略图?

-编辑-

现在,我有

 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;
它会打印出图像,但这样我就可以a...

1 个回复
最合适的回答,由SO网友:kraftner 整理而成

如果你看看next_post_link 您将看到它需要一个参数$link 作为第二个参数:

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

您的参数当前不包括帖子缩略图:

_x( \'%title <span class="meta-nav">&rarr;</span>\', \'Next post link\', \'nicosite\' )
所以我们需要这样添加:

$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\' ) );

结束

相关推荐