Paging with multiple loops in index
-
Hello,
I am trying to use multiple loops within my main index template to show first 5 posts as normal, and only show the titles and post information for another 15 posts.
The code I am using is as below:
<?php get_header(); ?> <div id="main" class="clearfix"> <div id="posts" class="grid_8"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php query_posts('showposts=5'); ?> <?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?> <?php static $count1 = 0; if ($count1 == "5") { break; } else { ?> <div class="post"> <div class="post-image"> <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail() ) : ?> <?php $src = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'large', false, '' ); ?> <img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo $src[0]; ?>&w=576&h=172&zc=1" border="0" alt="<?php the_title(); ?>" /> <?php else : ?> <?php if( get_post_meta( $post->ID, "image_value", true ) ) : ?> <img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>&w=576&h=172&zc=1" border="0" alt="<?php the_title(); ?>" /> <?php else : ?> <img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo wp_catch_first_image('l'); ?>&w=576&h=172&zc=1" border="0" alt="<?php the_title(); ?>" /> <?php endif; ?> <?php endif; ?> </div> <h1 class="post-title"><a href="<?php the_permalink(); ?>" title="Continue reading "<?php the_title(); ?>""><?php the_title(); ?></a></h1> <div class="post-meta clearfix"> <span class="datetime"><?php the_time('F jS, Y') ?></span> <span class="category"><?php the_category(', ') ?></span> <span class="comment"><?php comments_number('No Comment','1 Comment','% Comments'); ?></span> </div> <div class="post-excerpt"><?php wp_limit_post(200,'.'); ?></div> <span class="post-link"><a href="<?php the_permalink(); ?>" title="Read more about "<?php the_title(); ?>"">Read more »</a></span> </div> <?php $count1++; } ?> <?php endforeach; ?> <?php endwhile; endif; ?> // Begin posts as list <div class="post-small"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php query_posts('showposts=15'); ?> <?php $posts = get_posts('numberposts=15&offset=5'); foreach ($posts as $post) : start_wp(); ?> <?php static $count2 = 0; if ($count2 == "15") { break; } else { ?> <?php the_date('', '<br />', '<hr />'); ?> <h1 class="post-title-small"><a href="<?php the_permalink(); ?>" title="Continue reading "<?php the_title(); ?>""><?php the_title(); ?></a></h1> <div class="post-meta clearfix"> <span class="datetime"><?php if(!function_exists('how_long_ago')){the_time('F jS, Y'); } else { echo how_long_ago(get_the_time('U')); } ?> </span> <span class="category"><?php the_category(', ') ?></span> <span class="comment"><?php comments_number('No Comment','1 Comment','% Comments'); ?></span> </div> <?php $count2++; } ?> <?php endforeach; ?> </div> <?php endwhile; endif; ?> <div class="post-navigation clearfix"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></div> </div> <div id="sidebar" class="grid_4"> <?php get_sidebar(); ?> </div> </div> <?php get_footer(); ?>
The problem is, when I try to visit page 2 or any other page that displays the posts, it shows me the exact same posts. I am at my wits end to fix this, would really appreciate if someone could help me figure this out.
- The topic ‘Paging with multiple loops in index’ is closed to new replies.