• Hi guys,

    coming from this great discussion in the Customizr forum Page of Posts containing just one Category, then another Page by Category and using Rocco’s great template I just realized that when pagination is needed in my case more than 10 posts the page 2, 3, etc. give me a 404. Any help much appreciated as I am not good enough yet to figure this out by myself.
    When analyzing which template is used on page 2 I can see it falls back to the index.php template while before pagination it uses this page-of-posts.php template (see code below).

    <?php
    /*
     * Template Name: Page of Posts
     */
    
    /* Configuration */
    $design_layout = 'alternate'; /* or alternate */
    $show_page_title = true; /* or false */
    $show_page_content = true; /* or false */
    $number_of_posts = 0; /* -1 stays for unlimited, 0 will use the Maximum number of posts per page settings */
    /* bind a page to a category*/
    
    $page_category = array(
        // page_id => cat_id
        '7'  => '3',
        '40'  => '11',
        '426'  => '11'
    );
    /* will be overridden by the setting Show metas in home (if true) if you display this tempalate in home */
    $show_posts_metas = false; /* or false */
    
    /* query parameters here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters */
    $tc_posts_page_template_the_query = array(
      'post_type'      => 'post',
      'post_status'    => 'publish',
      'posts_per_page' => $number_of_posts ? $number_of_posts : get_option('posts_per_page'),
    );
    
    /* End of configuration */
    
    if ( array_key_exists( get_the_ID(), $page_category ) )
      $tc_posts_page_template_the_query = array_merge( $tc_posts_page_template_the_query, array( 'cat' => $page_category[get_the_ID()] ) );
    
    /* are we displaying this template in home? TODO handle pagination properly */
    if ( get_queried_object_ID() == get_option( 'page_on_front' )  && get_option('show_on_front') == 'page' ){
      /* display headings */
      if ( method_exists('TC_headings', 'tc_set_post_page_heading_hooks') ) {
        add_filter('tc_display_customizr_headings', '__return_false');
        TC_headings::$instance -> tc_set_post_page_heading_hooks();
      }
      $_page = get_query_var('page') ? get_query_var('page') : 1;
    }
    
    if ( 'alternate' == $design_layout )
      add_filter('tc_post_list_controller', '__return_true');
    else{
      add_filter('tc_is_grid_enabled', '__return_true');
      add_filter('tc_grid_do', '__return_true');
    }
    if ( $show_page_title )
      add_action('__before_loop', 'print_page_title', 0);
    
    if ( $show_page_content )
      add_action('__before_loop', 'print_page_content', 0); 
    
    if ( $show_posts_metas )
      add_filter('tc_show_post_metas', '__return_true');
    
    add_filter('tc_content_headings_separator', '__return_false');
    
    function print_page_title(){
    ?>
      <header class="entry-header">
        <h1 class="entry-title"><?php echo apply_filters('tc_the_title', get_the_title() ); ?></h1>
        <hr class="featurette-divider __before_content">
      </header>
    <?php
    }
    function print_page_content(){
    ?>
      <header class="entry-header">
        <div class="entry-content-page"><?php echo apply_filters('tc_page_content', the_content() ); ?></div>
        <hr class="featurette-divider __before_content">
      </header>
    <?php
    }
    add_action('__before_loop', 'tc_posts_page_template_query', 1);
    add_action('__after_loop', 'tc_posts_page_template_reset_query', 9999);
    
    function tc_posts_page_template_query() {
        global $wp_query, $tc_posts_page_template_the_query, $_page, $paged;
    
        $paged = $_page ? $_page : $paged;
    
        $wp_query = new WP_Query(
            array_merge( $tc_posts_page_template_the_query, array('paged' => $paged) )
        );
    }
    
    function tc_posts_page_template_reset_query(){
        global $wp_query, $wp_the_query;
        $wp_query = $wp_the_query;
    }
    get_template_part('index');
  • The topic ‘Page of Posts containing just one Category – Pagination Page 2 is broken 404’ is closed to new replies.