即使没有下一篇文章,有没有办法可以更改我的分页代码以查找下一篇或上一篇文章?因此,如果我在我的第一篇文章中它说“prev”,我也希望它接下来说,并找到最后一个发布。所以它循环帖子。不确定这是否可能
<div class="nav">
<ul>
<li><?php previous_post_link('%link', 'previous', TRUE); ?></li>
<li><?php next_post_link('%link', 'next', TRUE); ?></li>
</ul>
</div>
答案 0 :(得分:1)
是的,可以通过filters
。
/**
* Functon creates default content for pagination function previous_post_link() and next_post_link()
* @param $original string HTML content returned by previous_post_link/next_post_link to be modified
* @return string
*/
function default_prev_next_link($original) {
//if prev/next link does not exists, $original is empty string
if(!$original)
return "<a href='#'>new content</a>";
//you need to return original value, in case it is set
return $original;
}
//hook our function to filters
add_filter('previous_post_link', 'default_prev_next_link');
add_filter('next_post_link', 'default_prev_next_link');
最后,您可以创建两个单独的函数,分别挂钩到* _post链接