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

in my homepage I have content boxes with different layouts. Every box has an image and the post title corresponding to a single post. How should I use only one single get_posts() and format the layout of the boxes differently?


Post-title 1
Image 1 BIG

Post-title 2
Image 2 MEDIUM

Post-title 3
Image 3 SMALL
share|improve this question
what's the problem in this? You use $posts = get_posts(); echo $posts[0]['post_title']; echo $posts[1]['post_title']; echo $posts[2]['post_title']; – Mridul Aggarwal Oct 17 '12 at 18:14
I am also not sure what the problem/question is? – s_ha_dum Oct 17 '12 at 19:18
up vote 0 down vote accepted

As @MridulAggarwal already stated, it's a pretty basic PHP task that you're confronted with:

$wpse69584_posts = get_posts( array( /* Your Arguments */ ) );

echo $post[0]['post_title'];
echo isset( $post[0]->post_excerpt ) 
    ? apply_filters( 'the_excerpt', $post[0]->post_excerpt )
    : apply_filters( 'the_content', $post[0]->post_content )
// etc.

Or if you're using a loop, it's even easier:

global $wpdb;
if ( have_posts() )
    while( have_posts() )

        if ( 1 <= $wpdb->current_post )
             $thumb_size = 'BIG';
        // Add 'MEDIUM' to 2nd post and 'SMALL' to each other
             $thumb_size = ( 2 == $wpdb->current_post ? 'MEDIUM' : 'SMALL' );

        echo '<article '.get_post_class( "post-number-{$wpdb->current_post}" ).'>';
            echo "<h{$wpdb->current_post}>";
            echo "</h{$wpdb->current_post}>";


            the_post_thumbnail( get_the_ID(), $thumb_size );
        echo '</article>';

Note, that this won't work with a larger number as 6, as $wpdb->current_post will still increment, but there's simply no <h7> and following ;)

share|improve this answer
Really dummy question. Thanks for The answer. – Francesco Oct 18 '12 at 0:24

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.