1

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(); ?>
2
  • please review: codex.wordpress.org/The_Loop your code does not have the loop code after the query_posts line.
    – Michael
    Mar 6, 2012 at 14:29
  • You should avoid using showposts, it's been depreciated in favor of posts_per_page.
    – mor7ifer
    Mar 6, 2012 at 15:59

1 Answer 1

0

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> 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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