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.

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 ?>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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'.

share|improve this answer
    
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. –  Jeremy Love Mar 11 '11 at 18:30
    
I don't think you understood. See updated answer. –  scribu Mar 11 '11 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 –  Jeremy Love Mar 11 '11 at 19:30
    
Ah, logic fail. It's supposed to be $count < 1, not the other way around. Updated answer. –  scribu Mar 11 '11 at 20:02
    
Bingo! works now thanks –  Jeremy Love Mar 11 '11 at 20:20

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.