0

I'm trying to add pagination to my site but it isn't working. Here's the code:

 <div id="gridcontainer" class="carousel">
    <?php
    $currentPage = get_query_var('page');
    $counter = 1; //start counter
    $grids = 2; //Grids per row

    global $query_string; //Need this to make pagination work

    $mosaicoMenu = new WP_Query(array(
                'post_type' => 'artist',
                'orderby' => 'title',
                'order' => ASC,
                'posts_per_page' => 8,
                'page' => $currentPage
            ));  

    if($mosaicoMenu->have_posts()) :  
        while($mosaicoMenu->have_posts()) :  
            $mosaicoMenu->the_post(); 

    //Show the left hand side column
    if($counter == 1) :
    ?>
        <div class="griditemleft">
            <div class="artista no-padding no-margin" style="background-image: url(<?php the_post_thumbnail_url(); ?>), url('https://i.postimg.cc/9QS9Mn00/gradient2.png');">
                <p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?><span>+</span></a></p>
            </div>
        </div>

    <?php
    //Show the right hand side column
    elseif($counter == $grids) :
    ?>
        <div class="griditemright">
            <div class="artista no-padding no-margin" style="background-image: url(<?php the_post_thumbnail_url(); ?>), url('https://i.postimg.cc/9QS9Mn00/gradient2.png');">
                <p><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?><span>+</span></a></p>
            </div>
        </div>

        <div class="clear"></div>

    <?php
    $counter = 0;
    endif;

    $counter++;
    endwhile;

    echo paginate_links(array(
        'total' => $mosaicoMenu->max_num_pages
    ));
    endif;
    wp_reset_postdata();
    ?>
</div>

Everything looks fine but when I click on the pagination links it takes me to the same page. I'm using this on a static front page, btw.

1 Answer 1

0

It should be paged and not page

'paged' => $currentPage
5
  • Oh, thanks! This actually helped but now there's another problem. Once I go to the second page, I can't go back to the first. It's like they're both behaving as one page. Why would that be? Commented Feb 3, 2019 at 15:39
  • Since the get_query_var('page') takes values from the URL. You need to show us how the URL looks like when you back to the first page. Commented Feb 3, 2019 at 15:56
  • it's localhost/wordpress/page/2 (which makes sense, right?) but it won't even show the "previous page" link. Commented Feb 3, 2019 at 16:04
  • You should also change $current page line to $currentPage = get_query_var('paged',1); Commented Feb 3, 2019 at 16:51
  • just tried that but i still have the same problem... Commented Feb 3, 2019 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.