$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'); ?>wp query - Multiple WP_Query loops with Pagination Not Working|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)

wp query - Multiple WP_Query loops with Pagination Not Working

matteradmin11PV0评论

Please can anyone help me out here? I'm really stucked with this code.

I want to create a multi post loop on my home page with each loop having its own pagination.

The first loop is for recent post, while the second is for popular post and the last is for recommended posts.

Only the first loop pagination is working perfectly but the other two are not working. What could be wrong with my code? I know almost nothing about PHP.

I actually got the code from here ( = )

Can I also rap the pagination 'next' link with a div? Here is the code. `

    <?php
            $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
            $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
            $paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;

            // Custom Loop with Pagination 1
            // 
            $args1 = array(
                'paged'          => $paged1,
                'posts_per_page' => 8,
            );
            $query1 = new WP_Query( $args1 );

            while ( $query1->have_posts() ) : $query1->the_post();

            get_template_part( 'template-parts/content', get_post_format() );

            endwhile;

            // 
            $pag_args1 = array(
                'format'  => '?paged1=%#%',
                'current' => $paged1,
                'total'   => $query1->max_num_pages,
                'add_args' => array( 'paged2' => $paged2 )
            );
            echo paginate_links( $pag_args1 );
        ?>




         <div class="popular">
        <?php

             $popular_days_ago = "$popular_days days ago";
             $recent = new WP_Query
             (array( 'posts_per_page' => $number,
              'orderby' => 'meta_value_num', 
              'order' => 'DESC', 
              'meta_key' => 'post_views_count', 
              'date_query' => array( array( 'after' => $popular_days_ago )) ));

             $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
            $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
            $paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;

           // Custom Loop with Pagination 2
           $args2 = array(
            'paged'          => $paged2,
            'posts_per_page' => 2,
        );


        while ( $recent->have_posts() ) : $recent->the_post();
        get_template_part( 'template-parts/content-pop', get_post_format() );
        endwhile;

        $pag_args2 = array(
            'format'  => '?paged2=%#%',
            'current' => $paged2,
            'total'   => $recent->max_num_pages,
            'container'   => 'ul',
            'add_args' => array( 'paged1' => $paged1 )
        );
        echo paginate_links( $pag_args2 );

        ?>
    </div>

<?php

$paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
$paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1;
$paged3 = isset( $_GET['paged3'] ) ? (int) $_GET['paged3'] : 1;


            // Custom Loop with Pagination 3
            $args2 = array(
                'paged'          => $paged3,
                'posts_per_page' => 3,
            );
            $query3 = new WP_Query( $args3 );
            $query3 = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => $number )); 

            while ( $query3->have_posts() ) : $query3->the_post();
            get_template_part( 'template-parts/content-catlist', get_post_format() );

            endwhile;

            $pag_args3 = array(
                'format'  => '?paged3=%#%',
                'current' => $paged3,
                'total'   => $query3->max_num_pages,
                'add_args' => array( 'paged1' => $paged1 )
            );
            echo paginate_links( $pag_args3 );
        ?>

`

Post a comment

comment list (0)

  1. No comments so far