Twenty nineteen custom template pagination
-
Hello,
I’m creating a custom template for a page using a child of twenty nineteen. The custom query works and if I set the page length to less than the number of posts, to trigger pagination, the pagination appears. The problem is when to click on the next page the url changes to page 2 but the page content doesn’t change.<?php /* Template Name: Skils */ get_header(); ?> <section id="primary" class="content-area"> <main id="main" class="site-main"> <?php /*Page loop*/ /* Start the Loop */ while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content/content', 'page' ); // If comments are open or we have at least one comment, load up the comment template. if ( comments_open() || get_comments_number() ) { comments_template(); } endwhile; // End of the loop. /*End page loop*/ /*Post loop*/ // Define custom query parameters $custom_query_args = array('category_name' => 'how_to', 'posts_per_page' => 2); // Instantiate custom query $custom_query = new WP_Query( $custom_query_args ); // Pagination fix $temp_query = $wp_query; $wp_query = NULL; $wp_query = $custom_query; //print_r($custom_query); // Output custom query loop if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); // Loop output goes here get_template_part( 'template-parts/content/content' ); endwhile; endif; // Reset postdata wp_reset_postdata(); // Previous/next page navigation. twentynineteen_the_posts_navigation(); // Reset main query object $wp_query = NULL; $wp_query = $temp_query; /*End post loop*/ ?> </main><!-- #main --> </section><!-- #primary --> <?php get_footer();
I used the print_r to see the content of the $custom_query and the correct number of pages is shown but the content of only the first two posts is shown. If I change the page number to -1 all the page content is shown.
Thanks
Mark
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Twenty nineteen custom template pagination’ is closed to new replies.