遍历wordpress的the_post_navigation()函数 [英] Loop through wordpress' the_post_navigation() function
本文介绍了遍历wordpress的the_post_navigation()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以遍历 the_post_navigation()
函数?
现在,当我处于发布循环的结尾时,下一个发布"按钮将消失.我希望此按钮保持不变,并导航到第一篇文章.这样,导航就不断在帖子中循环.
Now, when I am at the end of the post loop, the 'next post' button simply disappears. I want this button to stay, and to navigate to the first post. This way, the navigation keeps looping through the posts.
这是代码btw:
<div class="case-nav hidden-xs">
<?php the_post_navigation( array(
'prev_text' => __( 'Previous post'),
'next_text' => __( 'Next post'),
)); ?>
</div>
编辑
这是源代码: http://www.codesend.com/view/333b7293fcc8994ae7938056cf8c6b1f/
推荐答案
这是一个较短的版本,用于帖子之间的无限循环.
This is a shorter version for infinite looping between posts.
/* Infinite next and previous post looping */
if( get_adjacent_post(false, '', true) ) {
previous_post_link('%link', '← Previous Post');
} else {
$first = new WP_Query('posts_per_page=1&order=DESC');
$first->the_post();
echo '<a href="' . get_permalink() . '">← Previous Post</a>';
wp_reset_query();
};
if( get_adjacent_post(false, '', false) ) {
next_post_link('%link', 'Next Post →');
} else {
$last = new WP_Query('posts_per_page=1&order=ASC');
$last->the_post();
echo '<a href="' . get_permalink() . '">Next Post →</a>';
wp_reset_query();
};
这篇关于遍历wordpress的the_post_navigation()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文