WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

OK so I've searched a lot and couldn't find a straight forward answer to my question. I am simply trying to use one category loop that will display posts in a category page in a wordpress site. lets say 6 posts for this purpose.

it's pretty simple to accomplish it by using a simple query loop like so:

<?php query_posts('showposts=6'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
// content or anything comes here
<?php endwhile; endif; ?>

however, I am trying to "break" my loop into 2 different layouts:

  1. 2 posts showing with featured image
  2. the rest of the 4 in a different design which will be just showing title + excerpt + read more

Here is a sample which best demonstrates what I am trying to accomplish: https://dl.dropbox.com/u/4405634/split-loop-layout.jpg

There are tons of solutions in the web, however some of the are too complicated and some don't work in a category loop.

I have seen it in a lot of websites and still can't find a simple way of doing it. does someone have a nice solution?

Thanks a lot. Gil

share|improve this question
I think @milo has answer, but one thing to mention - query_post() is Bad practice, Use pre_get_post filter instead. – amit Aug 12 '12 at 16:56
Try using "offset" - see my answer below. – Ciprian Aug 12 '12 at 19:23
Please go back and work on your older questions too! – kaiser Aug 13 '12 at 9:43
up vote 0 down vote accepted

Just create 2 queries using the "offset" parameter and separate them by:

<?php wp_reset_query(); ?>

Display posts from the 4th one (offset is starting from 0):

<?php $query = new WP_Query( 'offset=3' ) ); ?>

EDIT: Here's some sample code:

<?php query_posts('offset=0&showposts=2&order=ASC'); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endwhile; endif; ?>

<?php wp_reset_query(); ?>

<?php query_posts('offset=2&showposts=4&order=ASC'); ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endwhile; endif; ?>

That's it. You'll have 2 posts which you can style any way you want, and the next four, which, again, you can style differently.

share|improve this answer
can you write a sample of a working code? I am not that coder and not sure where to start. it will be great! thanks! – gil hamer Aug 12 '12 at 20:20
Why the negative vote? There are more ways to separate 2 queries and this is one of them. – Ciprian Aug 26 '13 at 13:48
Dont really remember why. it was long time ago when I rated it. anyway - it didn't work for me. I found another solution. changed your rating to positive. – gil hamer Sep 12 '13 at 10:54
This method/answer is by far inferior to the others as it requires you to do two separate queries. There is no need for that - Just count the index and apply the featured_template to count<=2. See Milo's or Syed Balkhi's answers... – Lulu Feb 19 '15 at 14:12
@Ciprian how would you break the loop to add an advertisement between a certain post number. – user32447 Aug 5 '15 at 20:50

check which post you're currently outputting via $wp_query->current_post:

    if ( have_posts() ) :
        while ( have_posts() ) :

                // first two post to show both title, excerpt
                if( 2 > $wp_query->current_post ) :

                //else (remaining) show only title    
                else :

share|improve this answer
Thanks @Milo tried your code but it didn't work, it gave me an error. – gil hamer Aug 12 '12 at 20:18
@gilhamer check for syntax error, coz this code is correct. – amit Aug 12 '12 at 21:40
Maybe I am doing something wrong. can you tell me how do I put the_title in the first post and the_excerpt in the second one? thanks – gil hamer Aug 12 '12 at 21:42
put the_title(); after if( 2 > $wp_query->current_post ) : to print it for first 2 posts and the_excerpt(); after else : to show on remaining posts. – amit Aug 12 '12 at 22:26
Hi Amit, your code really works, however, I have so much extra HTML to put in between and in this way of coding it makes it very complicated since you need to deal with echoing a lot of stuff and a lot of single and regular quotation marks. I will try anyway, thanks a lot – gil hamer Aug 13 '12 at 9:14

You can do this fairly easily by using a counter in your loop like this:

$counter = 1;
$myquery = new WP_Query( array( 'posts_per_page' => 6 ) );
while ( $myquery->have_posts() ) : $myquery->the_post(); 

if($counter == 1) { ?>

First post Look Different

<?php } else { ?>

Rest looks different

// Reset Post Data
share|improve this answer
this was actually working @Syed Balkhi but the problem is that it shows all posts regardless if I am in a certain category. I would like to get the first 6 posts but according to a certain category I am in. is it possible? – gil hamer Aug 12 '12 at 20:19
You can count posts directly in the query using $wp_query->current_post +1; – Wyck Aug 13 '12 at 3:40
can you please edit your code so I know where exactly to put it? thanks! – gil hamer Aug 13 '12 at 7:49

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.