【问题标题】:next_post_link previous_post_link dont disable when there is no next post, instead loop postsnext_post_link previous_post_link 在没有下一个帖子时不禁用,而是循环帖子
【发布时间】:2013-04-15 07:13:50
【问题描述】:
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">'; 
 };

如果没有下一篇文章,我发现此代码用于显示图像。但是如果我喜欢循环播放它,我的意思是如果没有上一篇或下一篇文章,只是在第一次或结尾循环,所以不会缺少导航按钮?

【问题讨论】:

  • 代码对我来说看起来不错,所以我不确定你在问什么:)

标签: wordpress navigation


【解决方案1】:

我只是在处理类似的问题。我只是将下一个和上一个相邻的帖子条件组合到一个 if 语句中......意思是如果下一个相邻的帖子或上一个相邻的帖子存在,那么做一些事情:

if ( (get_adjacent_post(false, '', true)) ||  (get_adjacent_post(false, '', false)) ) {
    // Do something if either previous or next post exists
    // You could even nest your original conditionals inside here
} else {
    // If neither exists, then do something different
}

我知道这已经晚了,但希望它对某人有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    相关资源
    最近更新 更多