• 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

    (@carol_bb)

    nobody has a idea to fix it? cheers, carol

    Thread Starter carol_bb

    (@carol_bb)

    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.