Title: continues(loop) page navigation with get_permalink()
Last modified: August 21, 2016

---

# continues(loop) page navigation with get_permalink()

 *  [carol_bb](https://wordpress.org/support/users/carol_bb/)
 * (@carol_bb)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/continuesloop-page-navigation-with-get_permalink/)
 * Hello,
    I already searched the forum with this problem and I found a lot of good
   information but I’m still not possible to solve my problem. I’m sorry about that.
 * I would like to turn my page navigation in to a loop. I’m quit close but my problem
   is that I’m not able to switch between the categories. At the moment I have a
   loop inside of the categorie but I’m not able to jump to the next categorie.
 * My script:
 *     ```
       <?php
       $prev_post = get_adjacent_post( true, '', true );
       $next_post = get_adjacent_post( true, '', false );
       $prev_post_id = $prev_post->ID;
       $next_post_id = $next_post->ID;
       ?>
       ```
   
 *     ```
       <?php
       if(($prev_post_id === '') || ($prev_post_id === null)) :
   
       $query = new WP_Query(array('order' => 'DESC', 'posts_per_page' => '1', 'cat=4'));
   
       if($query->have_posts()) : while($query->have_posts()) :
           $query->the_post();
           $prev_post_id = get_the_ID();
           endwhile;
       endif;
   
       wp_reset_postdata();
   
       endif;
   
       if(($next_post_id === '') || ($next_post_id === null) ) :
   
       $query = new WP_Query(array('order' => 'ASC', 'posts_per_page' => '1', 'cat=4'));
   
       if($query->have_posts()) : while($query->have_posts()) :
               $query->the_post();
               $next_post_id = get_the_ID();
           endwhile;
       endif;
   
       wp_reset_postdata();
   
       endif;
       ?>
       ```
   
 *     ```
       <div id="left">
       <a href="<?php echo get_permalink($prev_post_id); ?>" class="myCursorPrev">&nbsp;</a>
       </div>
       <div id="right">
       <a href="<?php echo get_permalink($next_post_id); ?>" class="myCursorNext">&nbsp;</a>
       </div>
       ```
   
 * `$query = new WP_Query(array('order' => 'ASC', 'posts_per_page' => '1', 'cat=
   4'));`
    I tried different usage with the cat=4 or cat=1,2,3,4 but it has no effect.
 * thanks for any help.
    best, carol

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [carol_bb](https://wordpress.org/support/users/carol_bb/)
 * (@carol_bb)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/continuesloop-page-navigation-with-get_permalink/#post-3909546)
 * nobody has a idea to fix it? cheers, carol
 *  Thread Starter [carol_bb](https://wordpress.org/support/users/carol_bb/)
 * (@carol_bb)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/continuesloop-page-navigation-with-get_permalink/#post-3909614)
 * Hello I’m getting closer and I can finally jum between one categorie into the
   next but after that it stop. So I’m still not able to loop through all the categories.
   I hope someone know a trick.
    best, Carol Update Code:
 *     ```
       <?php
       $prev_post = get_adjacent_post( true, '', true );
       $next_post = get_adjacent_post( true, '', false );
       $prev_post_id = $prev_post->ID;
       $next_post_id = $next_post->ID;
       ?>
   
       <?php
   
       if(($prev_post_id === '') || ($prev_post_id === null)) :
   
       $query = new WP_Query( array( 'category__in' => array( 2,3,4,1,5 ) ) );
   
       if($query->have_posts()) : while($query->have_posts()) :
           $query->the_post();
           $prev_post_id = get_the_ID();
           endwhile;
       endif;
   
       wp_reset_postdata();
   
       endif;
   
       if(($next_post_id === '') || ($next_post_id === null) ) :
   
       $query = new WP_Query( array( 'category__in' => array( 2,3,4,1,5 ) ) );
   
       if($query->have_posts()) : while($query->have_posts()) :
               $query->the_post();
               $next_post_id = get_the_ID();
           endwhile;
       endif;
   
       wp_reset_postdata();
   
       endif;
       ?>
       ```
   
 *     ```
       <div id="left">
       						<a href="<?php echo get_permalink($prev_post_id); ?>" class="myCursorPrev">&nbsp;</a>
       					</div>
       					<div id="right">
       						<a href="<?php echo get_permalink($next_post_id); ?>" class="myCursorNext">&nbsp;</a>
       					</div>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘continues(loop) page navigation with get_permalink()’ is closed to new
replies.

## Tags

 * [get_adjacent_post](https://wordpress.org/support/topic-tag/get_adjacent_post/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [navigation](https://wordpress.org/support/topic-tag/navigation/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [carol_bb](https://wordpress.org/support/users/carol_bb/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/continuesloop-page-navigation-with-get_permalink/#post-3909614)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
