0

I file all the galleries on my blog under the 'gallery' tag. I use the following code (via) to display the latest 7 gallery posts after the 8th latest post on home page:

<!-- Featured post galleries after 8th post -->
<?php
   $homegallery++;
   if ($homegallery == 8){
?>

<!-- Display Gallery Posts -->
<div id="gallery-posts">
<?php
    $count = 0;
    $some_featured_posts = new WP_Query(array('category_name' => 'apps', 'posts_per_page' => 5));
    while ($some_featured_posts->have_posts()): 
        $some_featured_posts->the_post();
        $count++;
?>

<?php the_post_thumbnail( 'thumbnail' ); ?>

<?php
    endwhile;
    wp_reset_postdata();
?>
</div><!-- Display Gallery Posts END -->

<?php
   };
?><!-- Featured post galleries END -->

As you can see, I use a thumbnail to represent each post <?php the_post_thumbnail( 'thumbnail' ); ?>, may look weird, but that's how I do it. But I would like to show the thumbnails of first two posts in one size (large), the third one in one size (medium) and the rest in another size (thumbnail).

How do I do this?


In case it helps, I've got this far with some help:

<?php
    $loop_first = 1;
    if ( ! isset ( $loop_first ) ) {

    // set featured image size for first post
    the_post_thumbnail( 'medium' );
    } else {

    // set featured image size for other posts
    the_post_thumbnail( 'thumbnail' );
    }
?>

The above code (I believe) allows me to show a different size image for the first post, and different size thumbnails for the rest of the posts.

2 Answers 2

1

Just use the $count variable that you are incrementing:

<?php
    $count = 0;
    $some_featured_posts = new WP_Query(array('category_name' => 'apps', 'posts_per_page' => 5));
    while ($some_featured_posts->have_posts()): 
        $some_featured_posts->the_post();
        $count++;

        if( $count <= 2 )
          the_post_thumbnail( 'large' ); 

        elseif( 3 == $count )
          the_post_thumbnail( 'medium' ); 

        else
          the_post_thumbnail( 'thumbnail' ); 


    endwhile;
    wp_reset_postdata();
?>
0

yes thats v great idea but the problem is that it repeats all the images for every condition i mean that it display all the images while we have a condition here like...

<?php $count = 0;
    $some_featured_posts = new WP_Query(array('category_name' => 'latest-products', 'posts_per_page' => 6));
    while ($some_featured_posts->have_posts()): 
        $some_featured_posts->the_post();
        $count++;

    if( $count == 0 )?>
    <div class="first-row" style="float:left">
    <div class="first-img"><?php the_post_thumbnail( array(200,400) ); ?></div>
   <?php  if  ( $count == 1 )  ?>
    <div class="second-img"><?php the_post_thumbnail( array(100,100) ); ?></div>

    </div>
     <?php if( 2 == $count ) ?>
      <div class="second-row" style="float:left">
    <div class="secondrow-first-img"><?php the_post_thumbnail( array(200,300) ); ?></div>
          <?php if( 3 == $count ) ?>
    <div class="secondrow-second-img"><?php the_post_thumbnail( array(100,75) ); ?></div>
     <?php if( 4 == $count ) ?>
    <div class="secondrow-third-img"><?php the_post_thumbnail( array(400,300) ); ?></div>

    </div>
     <?php if( 5 == $count ) ?>
      <div class="third-row" style="float:left">
    <div class="thirdrow-first-img"><?php the_post_thumbnail( array(200,500) ); ?></div>


    </div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.