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.

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?

Example:

H1
Post-title 1
Image 1 BIG

H2
Post-title 2
Image 2 MEDIUM

H3
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

1 Answer 1

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() )
    {
        the_post();

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

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

            the_content();

            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

 
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.