Paging fails when custom template used for home page
-
I have created a custom page template which I believe would be considered a “showcase” type in that it allows static text, but when viewed, includes a post stream (in all but one excluded category, specified using a custom variable). This template works correctly, including paging of the post stream. However, as soon as I designate the page to be my home page, the paging stops working: I get the 4 most recent posts (plus a sticky one) but when I click on “<– Older posts”, I do see “/page/2” appended to the URL (which is the site URL since this is the home page) but I still get only the same set of recent posts.
Site URL: https://allsaintschelms-new.dreamhosters.com/
Here is the code for the template:<?php /* Template Name: X-Category */ /* This example is for a child theme of Twenty Twelve: * You'll need to adapt it the HTML structure of your own theme. */ get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php /* The loop: the_post retrieves the content * of the new Page you created to list the posts, * e.g., an intro describing the posts shown listed on this Page.. */ if ( have_posts() ) : while ( have_posts() ) : the_post(); // Display content of page get_template_part( 'content', get_post_format() ); wp_reset_postdata(); endwhile; endif; $category = get_post_meta( $posts[0]->ID, 'category', true ); $cat = get_cat_ID( $category ); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $post_per_page = 4; // -1 shows all posts $do_not_show_stickies = 0; // 0 to show stickies $args=array ( 'category__not_in' => array( $cat ), 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'posts_per_page' => $post_per_page, 'ignore_sticky_posts' => $do_not_show_stickies ); $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query( $args ); ?> <?php if ( $wp_query->have_posts() ) : ?> <div class="catsec"> <?php global $more; /* The loop */ ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <?php $more = 0; // Display content of posts ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php twentytwelve_content_nav( 'nav-below' ); ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> </div><!-- .catsec --> </div><!-- #content --> <?php $wp_query = null; $wp_query = $temp; ?> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
- The topic ‘Paging fails when custom template used for home page’ is closed to new replies.