"next page" of parent in infinite loop

I'm trying to include a "Next Service" button on a website that hopefully take you to the next page under

I'm trying to include a "Next Service" button on a website that hopefully take you to the next page under the Services page (Parent) so no matter which service you are on, it can loop through to the next (regardless if it's the first or last page).

However the code I have does that but when it gets to the last one, it carries on to the next page - regardless of the fact it's not under 'Services'.

<?php 
    $nextPost = get_next_post();
    if($nextPost) {
        $nextPostID = $nextPost->ID;
?>
    <a href="<?php echo get_permalink( $nextPostID ); ?>" >
        ID <?php echo get_the_id( $nextPostID ); ?> - <?php echo get_the_title( $nextPostID ); ?>
    </a>
<?php } else {
        $first_post = get_posts( array(
            'post_type' => 'page',
            'posts_per_page'   => 1,
            'order' => 'ASC'
        ) );
        ?>
        <a href="<?php echo get_permalink( $first_post[0]->ID ); ?>" >
            First: <?php echo get_the_title( $nextPostID ); ?>
        </a>
<?php } ?>
<?php wp_reset_postdata(); ?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744940247a4602276.html

相关推荐

  • &quot;next page&quot; of parent in infinite loop

    I'm trying to include a "Next Service" button on a website that hopefully take you to the next page under

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信