[英]Infinite next/prev post loop
Using the code below, I'm trying to set an infinite next/prev post loop solely for pages (as opposed to posts). 使用下面的代码,我试图为页面(而不是帖子)设置一个无限的next / prev post循环。 The last page I have, the previous button links to a page, but the next button links to the first post I have available.
我有最后一页,前一个按钮链接到一个页面,但下一个按钮链接到我可用的第一篇文章。 How can I change it to only target pages?
如何将其更改为仅目标页面?
<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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.