WordPress.org

Ready to get started?Download WordPress

Forums

custom post types get_adjacent_post infinite loop (1 post)

  1. jeffhack
    Member
    Posted 2 months ago #

    Hi, Using the code below, I'm trying to set an infinite next/prev post loop for single posts. when i'm on the last post, the next button have to jump into the first post. The previous button on the first post is working fine and links into the last post. Why the next button did not the same ?

    Thanks!

    <?php
        /**
         *  fleche infini loop
         */
        if( get_adjacent_post(false, '', true) ) {
             ?><div class="fleche-menu">
                    <span class="fleche-prev-menu"><?php previous_post_link('%link','<img src="<?php bloginfo('template_directory'); ?>/images/fleche-g.png"/>'); ?></span>
                    </div>  <?php
        } else {
            $first = new WP_Query('post_type=menus&posts_per_page=1&order=ASC');   $first->the_post();
                 ?><div class="fleche-menu">
                    <span class="fleche-prev-menu"><?php echo '<a href="' . get_permalink() . '">'; ?><img src="<?php bloginfo('template_directory'); ?>/images/fleche-g.png"/></a> </span>
                    </div>  <?php
    
                     wp_reset_query();
        };
    ?>
    
    <?php
        if( get_adjacent_post(false, '', false) ) {
             ?><div class="fleche-menu">
                    <span class="fleche-next-menu"><?php next_post_link('%link','<img src="<?php bloginfo('template_directory'); ?>/images/fleche-d.png"/>'); ?></span>
                    </div>  <?php
        } else {
             $last = new WP_Query('post_type=menus&posts_per_page=1&order=DESC');  $last->the_post();
                 ?><div class="fleche-menu">
                    <span class="fleche-next-menu"><?php echo '<a href="' . get_permalink() . '">'; ?><img src="<?php bloginfo('template_directory'); ?>/images/fleche-d.png"/></a> </span>
                    </div>  <?php
    
                     wp_reset_query();
        };
    ?>

Reply

You must log in to post.

About this Topic