$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>loop - Custom Query Pagination not working on static front page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

loop - Custom Query Pagination not working on static front page

matteradmin10PV0评论

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('.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('.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.

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/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/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.

Share Improve this question asked Feb 3, 2019 at 14:08 lulufvlulufv 51 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It should be paged and not page

'paged' => $currentPage
Post a comment

comment list (0)

  1. No comments so far