Creating an Image gallery with Loop – Pagination
-
Hi there,
I am trying to create an image gallery for my own custom WP theme.
I am making use of a loop which shows me the thumbnails of the images found among the uploads. This is working fine, however I also wish to have a pagination function for the gallery.
The pagination nav shows up but when I click a link to page 2 or more, the page is not found (404).(I am not a pro at coding…)
I have used this code (which is five years old) to get where I am at:<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $loopb = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 2, 'paged' => $paged ) ); ?> <?php while ( $loopb->have_posts() ) : $loopb->the_post(); //display posts ?> <?php endwhile; ?> <?php if($loopb->max_num_pages>1){?> <p class="navrechts"> <?php for($i=1;$i<=$loopb->max_num_pages;$i++){?> <a href="<?php echo '?paged=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a> <?php } if($paged!=$loopb->max_num_pages){?> <a href="<?php echo '?paged=' . $i; //next link ?>">></a> <?php } ?> </p> <?php } ?>
(This code is taken from here: https://wordpress.org/support/topic/adding-pagination-to-a-wp_query-loop#post-1516156 )
Can anyone tell me, why the pagination does not work properly?
Thanks for your time. Foolix
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Creating an Image gallery with Loop – Pagination’ is closed to new replies.