使用下面的代码,我试图为页面设置一个无限的next/prev-post循环(与posts相反)。我拥有的最后一页,上一个按钮链接到一个页面,但下一个按钮则链接到我可用的第一篇文章。如何将其更改为仅针对目标页面?
<div class="port-nav left">
<?php
/**
* Infinite next and previous post looping in WordPress
*/
if( get_adjacent_post(false, '', true) ) {
?>
<p class="prev"><?php previous_post_link('%link'); ?></p>
<?php
} 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();
};
?>
<?php
if( get_adjacent_post(false, '', false) ) {
?>
<p class="next"><?php next_post_link('%link'); ?>
<?php
} 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();
};
?>
</div>
这是在黑暗中拍摄的,因为我目前无法测试:
$last = new WP_Query('post_type=page&posts_per_page=1&order=ASC');