WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make a so called featured category on my theme homepage. In that category I would like to display 6 posts from same category. The problem is that, I would like to devide these posts into three different html blocks. For example:

<div>first 2 posts goes here</div>
<div>second 2 posts goes here</div>
<div>last 2 posts goes here</div>

The three divs have different html structure (eg. post image size etc). So, does it mean that I have to run 3 separate queries to get the above posts from the same category? Or would that be too much of load and I should use only one post query? Thanks.

share|improve this question

Just add a counter to the loop.

Just use $wp_query->current_post

while ( have_posts() ) : the_post();
    if($wp_query->current_post <= 1) // 1 because counter starts at 0
        // <div>first 2 posts go here</div>

    if($wp_query->current_post > 1 <= 3)
        // <div>second 2 posts go here</div>

    if($wp_query->current_post > 3 <= 5)
        // <div>last 2 posts go here</div>
share|improve this answer
You don't need a separate counter, wordpress has one already at $wp_query->current_post – Mridul Aggarwal Oct 26 '12 at 10:03
ah, didn't know that. Thx, I've edited the answer. – xsonic Oct 26 '12 at 10:36

You don't need multiple queries. You don't even need to put them all in a loop. For your example

while(have_posts()) :

    //display post



    //display post
share|improve this answer

Your Answer


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.