WordPress.org

Ready to get started?Download WordPress

Forums

continues(loop) page navigation with get_permalink() (3 posts)

  1. carol_bb
    Member
    Posted 9 months ago #

    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

  2. carol_bb
    Member
    Posted 9 months ago #

    nobody has a idea to fix it? cheers, carol

  3. carol_bb
    Member
    Posted 8 months ago #

    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>

Reply

You must log in to post.

About this Topic