Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to set up multiple loops on a page. The first loop will display the latest four blog posts, and the second loop below it will display the latest eight blog posts with pagination.

I set up the template below but only the first four blog posts show. Ideally, four blog posts for the first loop would show, then the same four would show in the second loop right below it. Did I misunderstand something? Can someone help me figure out where I went wrong?

    <?php get_header();?>

        <div id="content">
            <h2>Latest News</h2>
            <div id="latest-news">

                <?php
                    $featuredPosts = new WP_Query();
                    $featuredPosts->query('showposts=4');

                    while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
                ?>

                <div class="post" id="post-<?php the_ID(); ?>">
                    <div class="description">
                        <h3><?php the_title_attribute(); ?></h3>
                        <p><?php the_content_rss('', TRUE, '', 20); ?></p>
                    </div>
                </div>

                <?php endwhile; ?>

            </div>
            <div id="blog-list">
                <?php query_posts( array(
                      'posts_per_page' => 8,
                      'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
                 ));
                ?>
            </div>
        </div>

    <?php get_footer(); ?>
share|improve this question
    
please review: codex.wordpress.org/The_Loop your code does not have the loop code after the query_posts line. –  Michael Mar 6 '12 at 14:29
    
You should avoid using showposts, it's been depreciated in favor of posts_per_page. –  m0r7if3r Mar 6 '12 at 15:59
    
@m0r7if3r - thanks, duly noted. –  John Mar 7 '12 at 1:36

1 Answer 1

up vote 0 down vote accepted

add the loop code to the query_posts section;

example:

<div id="blog-list">                 
  <?php query_posts( array(                       
  'posts_per_page' => 8,                       
  'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),                  
  ));                 
  if( have_posts() ) : while( have_posts() ) : the_post(); ?>             

    <div class="post" id="post-<?php the_ID(); ?>">                     
      <div class="description">                         
        <h3><?php the_title_attribute(); ?></h3>                         
        <p><?php the_content_rss('', TRUE, '', 20); ?></p>                     
      </div>                 
    </div> 

  <?php endwhile;
  else : echo 'nothing found';
  endif; ?>
</div> 
share|improve this answer
    
Thanks, can't believe I forgot that part. –  John Mar 7 '12 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.