wordpress:previous_post_link()/next_post_link() 占位符 [英] wordpress: previous_post_link() / next_post_link() placeholder
问题描述
我在使用 previous_post_link()
和 next_post_link()
功能时遇到问题.当没有以前的帖子时,函数 previous_post_link()
不显示链接,对于 next_post_link()
和最后一个帖子也是如此.我想要一个占位符图像,以便设计保持一致.
I am having trouble with the previous_post_link()
and next_post_link()
functionality. When there is no previous post, the function previous_post_link()
does not display a link, likewise for the next_post_link()
and the last post. I would like to have a placeholder image so that the design stays consistent.
目前我有指向左和右的绿色箭头的图像,如果没有更多的帖子可以返回,我想放置一个灰色箭头的图像.
Currently I have images of green arrows pointing left and right, I would like to place an image of a grey arrow if there are no more posts to go back to.
有没有办法使用 next_post_link()
/previous_post_link()
函数但不删除链接.
Is there a way to use the next_post_link()
/previous_post_link()
functions but not have the link removed.
我也想知道有没有办法让链接循环,这样如果你来到最近的帖子,下一个帖子的链接就会把你带回到第一个帖子.
I also wonder if there is a way for the links to cycle, so that if you come to the most recent post, the next post link would bring you back to the first post.
************ 更新 ************
************ UPDATED ************
这是基于silent's"建议(接受的答案)使用 get_adjacent_post()
的代码:
Here is the code, based on "silent's" advice (accepted answer) to use 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">';
};
?>
推荐答案
我自己从来没有尝试过.但是,您可以参考这篇文章.它使用 get_adjacent_post().
I never try this myself. However, you may refer to this post. It uses get_adjacent_post().
这篇关于wordpress:previous_post_link()/next_post_link() 占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!