Support » Theme: Baskerville » Pagination problems when index hacked for multiple loops

  • Hi,

    Hope you can point me in the right direction here…

    I’ve hacked the index of your beautiful theme so that it goes through the WP Loop twice – based on http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action.

    Everything is hunky dory except for content of the posts when paginated.

    The pagination correctly counts the number of posts and calculates the number of pages (eg properly displays “Page 3 of 5”) – but the page content always shows the same most recent x posts…

    Afraid I’m a bit too stupid to figure this out just now…

    A stripped-down version of the code:

    <?php get_header(); ?>
    
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $total_post_count = wp_count_posts();
    $published_post_count = $total_post_count->publish;
    $total_pages = ceil( $published_post_count / $posts_per_page );
    
    if ( "1" < $paged ) : ?>
    
    <h5><?php printf( __('Page %s of %s', 'baskerville'), $paged, $wp_query->max_num_pages ); ?></h5>
    
    <?php endif; ?>
    
    <?php /* First Loop	 */ ?>
    
    <?php $my_query = new WP_Query( 'cat=-1' ); //exclude posts from category 1 ("Blog") ?>
    
    	<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    
    		<?php $do_not_duplicate[] = $post->ID; ?>
    
    		<?php get_template_part( 'content', get_post_format() ); ?>
    
    	<?php endwhile; ?>
    
    	<?php if ( $wp_query->max_num_pages > 1 ) : ?>
    
    	<?php echo get_next_posts_link( '&laquo; ' . __('Older posts', 'baskerville')); ?>
    
    	<?php echo get_previous_posts_link( __('Newer posts', 'baskerville') . ' &raquo;'); ?>
    
    <?php endif; ?>
    
    <?php /* Second Loop	*/ ?>
    
    <?php $my_query2 = new WP_Query( 'cat=1' ); // posts from category 1 ("Blog") ?>
    
    <?php while ( $my_query2->have_posts() ) : $my_query2->the_post(); ?>
    
    	<?php if ( in_array( $post->ID, $do_not_duplicate ) ) continue; ?>
    
    	<?php get_template_part( 'content', get_post_format() ); ?>
    
    <?php endwhile; ?>
    
    <?php get_footer(); ?>
  • The topic ‘Pagination problems when index hacked for multiple loops’ is closed to new replies.