0

Im trying to make different querys in my category like one with a offset of post and one that shows one post but while it continues to go through the loop, this is what i have but the loop keeps repeating itself i almost think im not doing it correctly. Anyone know whats wrong?

<?php if (have_posts()) : $count = 0; ?>

                                <div id="featured-category">
                                <div class="heading"><h2 class="recent-post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2></div>
                                <?php query_posts('showpost=1'); ?> 
                                <?php while (have_posts()) : the_post(); ?>
                                <div class="FC-image">
                                </div>
                                </div>
                                <?php endwhile ?>
                                <?php wp_reset_query(); ?>

                                <div id="recent-posts">
                                <!-- Post Starts -->
                                <div class="post">
                                <?php query_posts('showpost=4&offset=1'); ?> 
                                <?php while (have_posts()) : the_post(); ?>                 
                                <div class="post-img">                  
                                </div>
                                <div class="heading"><h2 class="recent-post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2></div>
                                <div class="recent-post-content">
                                <?php get_the_excerpt_limit( 200, '...&nbsp;Read More&nbsp;&raquo;' ); ?>                   
                                </div><!-- /.heading -->                    
                                </div><!-- /.post -->
                                <?php endwhile ?>
                                <?php wp_reset_query(); ?>


                                <?php query_posts('offset=4'); ?> 
                                <?php while (have_posts()) : the_post(); ?>
                                <div class="post">
                                <div class="heading"><h2 class="recent-post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2></div>
                                <div class="recent-post-content two">

                                <?php get_the_excerpt_limit( 200, '...&nbsp;Read More&nbsp;&raquo;' ); ?>                   

                                </div><!-- /.heading -->

                                </div><!-- /.post -->
                                <?php endwhile ?>
                                <?php wp_reset_query(); ?>        
                                <?php endwhile ?>

1 Answer 1

2

That's a really inefficient way to do it.

Just use the $count variable you declared at the top, without any query_posts():

$count = 0;
while ( have_posts() ) : the_post();

if ( $count < 1 ) {
  // first post
} elseif ( $count <= 4 ) {
  // next 4 posts
} else {
  // rest of the posts
}

$count++;
endwhile;

Also, it's 'showposts' not 'showpost'. Or use the newer 'posts_per_page'.

4
  • well it partly works, but for some reason it doesn't show my second query, the one that has showposts im guessing its because of the elseif statement. Mar 11, 2011 at 18:30
  • I don't think you understood. See updated answer.
    – scribu
    Mar 11, 2011 at 18:59
  • i understand but the way its posted its shows up on my site as all one posted field this is how i applied your code to it pastebin.com/t5CiZaUZ i appreciate you taking time out to help Mar 11, 2011 at 19:30
  • Ah, logic fail. It's supposed to be $count < 1, not the other way around. Updated answer.
    – scribu
    Mar 11, 2011 at 20:02

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.