• Resolved foolix

    (@foolix)


    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)
  • Thread Starter foolix

    (@foolix)

    After some more trying out the problem has been resolved.
    I believe the problem was:
    I was trying to use the code in a category page-

    It seems I had to create a custom page template rather than using the code in a category page.

    ( I was using a “category-gallery.php” and used mydomain.xy/category/gallery/.
    Now I am using “page-gallery.php” with a comment line
    // * Template Name: Gallery
    and am looking at the page through mydomain.xy/gallery , which has the page-template “Gallery” assigned to it.

    Good night. Foolix

Viewing 1 replies (of 1 total)
  • The topic ‘Creating an Image gallery with Loop – Pagination’ is closed to new replies.