我在previous_post_link()
和next_post_link()
功能中遇到问题。如果没有以前的帖子,功能previous_post_link()
不会显示链接,对于next_post_link()
和最后一篇帖子也是如此。我想要一个占位符图像,以便设计保持一致。wordpress:previous_post_link()/ next_post_link()占位符
目前我有指向左和右的绿色箭头的图像,如果没有更多帖子可以返回,我想放置一个灰色箭头的图像。
有没有办法使用next_post_link()
/previous_post_link()
功能,但没有链接删除。
我也想知道是否有链接循环的方式,这样如果你来到最近的帖子,下一篇文章链接会让你回到第一篇文章。
************修订************
下面是代码的基础上,“沉默的”建议(接受的答案)使用get_adjacent_post()
:
<?php
if(get_adjacent_post(false, '', true)) {
previous_post_link('%link','<img src="larr.gif"/>');
}
else {
echo '<img src="larr2.gif"/>';
};
if(get_adjacent_post(false, '', false)) {
next_post_link('%link','<img src="rarr.gif"/>');
}
else {
echo '<img src="rarr2.gif">';
};
?>